InanisAtheos
InanisAtheos

Reputation: 632

Umbraco: Create a tickbox-list which will define what content to add to a page

Ok, so I've recently started to learn setting up sites in Umbraco, as a client of mine wishes to have it for their site. Now, in their site, they want to have three types of "actions" which they should be able to add to any of their pages. These actions are really just a line of HTML. The way they wish to add it to the page however, is not to copy/paste a line of code (understandable..,) but rather have a tickbox-area.

The lines of code look like this:

<a class="action people" href="/link/"><span>Testimonials</span></a>

<a class="action rac" href="/link/"><span>Request a Call</span></a>

<a class="action contact" href="/link/"><span>Contact Us</span></a>

In short, the user needs to be able to tick in for example "Testimonials", save and publish to page and have the first line of code appear.

I tried going into Developer > Data Types > Create and defining my own based on a Checkbox list, but that's obviously wrong because there is no where to define a "when user ticks this box, save "this" as HTML and insert it into the page"

Edit:

Below, Marapet gave me the push in the right direction I needed. Instead of using a Razor script as he suggested, since I have no knowledge of Razor whatsoever, I decided to finalize the problem with XSLT, so in order to complete the answer, here's the code for that. (This goes in an xslt file referenced by the macro that Marapet suggested.)

<xsl:choose>
  <xsl:when test="$currentPage/actionTestimonials = '1'">CODE HERE</xsl:when>
  <xsl:otherwise></xsl:otherwise>
</xsl:choose>

<xsl:choose>
  <xsl:when test="$currentPage/actionContactUs = '1'">CODE HERE</xsl:when>
  <xsl:otherwise></xsl:otherwise>
</xsl:choose>

<xsl:choose>
  <xsl:when test="$currentPage/actionRequestACall = '1'">CODE HERE</xsl:when>
  <xsl:otherwise></xsl:otherwise>
</xsl:choose>

Upvotes: 0

Views: 837

Answers (1)

marapet
marapet

Reputation: 56446

If those links will always be displayed in the same place (for example footer, sidebar, ...):

  • Create a base document type which contains all the properties which are common to all pages (this is good practice, also for data such as meta description etc)
  • In the base document type, add a checkbox for each link
    • Go to Settings - Document types and select your base document type
    • Go to the tab Generic properties
    • In the drop-down below Add New Property, select True/false - this will give you a checkbox.
  • Make all the other document types which represent pages inherit from this base type - at least the ones which are supposed to show those links
  • Create a macro with a script which displays those links depending on the values in the checkbox fields
    • Go to the Developer section and add a script to Scripting files - make sure the Create macro checkbox is checked
    • In the script file, add the code to show or hide the links. You can use Razor to access the properties you created in the base document type, something like: if (Model.MyProperty) { ... }
  • In your main layout (masterpage), where the links are supposed to appear, insert the macro
    • Similar to : <umbraco:Macro Alias="MyMacro" runat="server" /> - you can use UI buttons in Umbraco to insert the code.

Upvotes: 1

Related Questions