3

My client has requested the ability to turn a specific, site-wide feature on and off from the site-wide header. It’s a link to a specific page that they would like to “turn on” months after the launch. Removing the link makes leaves a bit of a gaping hole, so I’ve created a special class to be applied to the header element to make some other content take up that space.

I can switch this class on and off by using a snippet or global variable, but I would like to allow my client to change this setting at will without granting them access to design preferences and templates. Is there a cost-effective add-on that would allow me to provide this one on/off switch that my templates can then test for?

I’ve seen Panel and it looks great, but I’d be paying $35 for a whole lot of functionality I won’t be using.

3

I'd likely just do it with a channel entries loop - if only to take advantage of native publish and expiry date functionality so the client can schedule the publishing and hiding of the link you're referring to with ease, particularly if there is any changing content within the feature you're describing (which could then be handled on an entry by entry basis). And if no custom fields are actually needed within the loop, using the disable parameter you can knock the queries down to a minimal level and use the cache parameter to reduce it further still.

1
  • Thanks! I thought adding a loop would be wasteful somehow, but this is a single-entry channel anyway, so the difference is imperceptible. I’m marking your answer as accepted. However, because this is —and always will be— a single-entry channel, I decided to use the status field. If the status is anything but open, the loop returns no results. I’m using a no_results conditional to set a stash variable for the class and voilá. – Alfonso Dec 17 '13 at 19:00
2

I’ve accepted Jean’s answer above, but wanted to document my own solution.

Because this particular case involved querying a single-entry channel, I simply used the status field of the entry to “turn the page on or off”, as it were. Any status that is not Open (that is, Draft or Closed) will yield zero results in my loop, so I use a no_results conditional to set a stash variable with the class I need to make things right. See below:

{exp:channel:entries url_title="special-page" dynamic="no"}
  {if no_results}
    {exp:stash:set name="special-button"} my-special-class{/exp:stash:set}
    {!-- Notice space before special class. --}
  {/if}
{/exp:channel:entries}

<header class="masthead{exp:stash:get name='special-button' process='end'}" id="masthead">
<!-- Variable contains space. -->

If the page status is Open, then the stash variable is not set, and no class is set.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.