ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Fresh Variables

November 21, 2007 10:20am

Subscribe [24]
  • #16 / Nov 21, 2007 5:31pm

    Mark Bowen

    12637 posts

    Hi Derek,

    Hmm still a little confused with this as I would just set the date format in the template myself but I can see that if you don’t want to allow access to the templates then this would be a good thing to enable. Problem being if someone puts something into the variable incorrectly then the site could stop working anyway. Ah well I suppose it’s down to the way you use it I guess.

    With your second example I didn’t quite understand what you meant by it. How exactly would this help someone who doesn’t allow anyone else access to the back-end and wants to make things easier for themselves. For instance I have a couple of sites that only I ever access on the back-end so my question would be how and in what instances could this help me out at all?

    Thanks.

    Best wishes,

    Mark

  • #17 / Nov 21, 2007 5:36pm

    Ryan M.

    1511 posts

    Derek, I think this might help solve an issue I’ve come across a few times tying to set a status parameter (template bloat due to repeating entries tags), based on whether one is logged in or not. I could never seem to wrap my head around getting that to work without repeating the whole entries block.

    Instead of:

    {if member_group == "1"}
    {exp:weblog:entries weblog="weblog1" status="Draft|Pending|Open"}
      {title}
    {/exp:weblog:entries}
    {if:else}
    {exp:weblog:entries weblog="weblog1" status="Open"}
      {title}
    {/exp:weblog:entries}
    {/if

    I'm assuming I can now just use:

    {exp:weblog:entries weblog="weblog1" status="{fv_status}"}
      {title}
    {/exp:weblog:entries}

    In the {fv_status} variable I could then do a conditional?

    {if member_group == "1"}Draft|Pending|{/if}Open

    So if I’m logged in the variable results in:

    {exp:weblog:entries weblog="weblog1" status="Draft|Pending|Open"}

    And if one is not logged in:

    {exp:weblog:entries weblog="weblog1" status="Open"}

    Seems to me I remember trying that monkey-business on/in the template once and I couldn’t get that to work, but maybe using Fresh Variables will do the trick?

  • #18 / Nov 21, 2007 5:38pm

    Derek Jones

    7561 posts

    Mark, what if you use this date format on variables in 30 different templates.  Don’t you think this is better than having a dynamically assigned variable in each of those templates?  And simpler to update if necessary?  Of course, most sites will not want to give content authors access to this module.  But it can simplify your own development, or tasks that administrators can accomplish.  Like on the second example.  Let’s say you create a new weblog, and you need to add that weblog to the weblog= parameter of 40 different weblog entries tags scattered among your templates.  Isn’t it easier to just edit this one Fresh Variable?

  • #19 / Nov 21, 2007 5:41pm

    Derek Jones

    7561 posts

    No, Ryan, this is just early-parsed text replacement.  If it won’t work in a regular template, it won’t work with Fresh Variables.  Fresh Variables allows you to do the same thing as using path.php variables: to have some of your template generated dynamically instead of having to code everything in manually in each template where things are repeated.  It does not do any parsing of the content of the variable itself, it merely substitutes it for you as needed.

  • #20 / Nov 21, 2007 5:51pm

    Derek Jones

    7561 posts

    You still must take care, Victor, of who you give access to this module.  In your above example, what if they set the mama_limit_homepage variable to:

    10"}{embed="some/template</code></pre>
    
    Then you have:
    
    <pre><code>{exp:weblog:entries weblog="mama" limit="10"}{embed="some/template"}

    The primary purpose is to make the administrator / developer’s life easier, giving a CP front end to a tool that normally requires FTP access, and even removes the content restrictions that the original tool had.  This module accepts anything that you could put into a template.  HTML, EE tags, PHP, Javascript, etc.

  • #21 / Nov 21, 2007 5:52pm

    Derek Jones

    7561 posts

    Actually, Victor, no, that conditional example won’t work.

  • #22 / Nov 21, 2007 6:01pm

    Mark Bowen

    12637 posts

    Mark, what if you use this date format on variables in 30 different templates.  Don’t you think this is better than having a dynamically assigned variable in each of those templates?  And simpler to update if necessary?  Of course, most sites will not want to give content authors access to this module.  But it can simplify your own development, or tasks that administrators can accomplish.  Like on the second example.  Let’s say you create a new weblog, and you need to add that weblog to the weblog= parameter of 40 different weblog entries tags scattered among your templates.  Isn’t it easier to just edit this one Fresh Variable?

    Thanks Derek. I think I understand a little better now. Will take a long hard look at all the sites I make from now on to see if I can simplify anything along the way. I’m sure this will come in handy somewhere! 😊

    Derek is trying to hard 😊

    Here is an easy example:
    A client wants to be able to control how many entries are displayed on the frontpage.

    Normally you would do this:

    {assign_variable:mama_limit_homepage="10"}
    
    {exp:weblog:entries weblog="mama" limit="{mama_limit_homepage}"}

    And you would give the client access to the templates and instruct them to change the value of mama_limit_homepage=“10” (god forbid they mess up my templates !!)

    Now it’s different.
    You go to the module and make a new variable called: mama_limit_homepage and give it a value of 10
    you can use {mama_limit_homepage} in your templates now.

    {exp:weblog:entries weblog="mama" limit="{mama_limit_homepage}"}

    Now you don’t need to give a client access to the template, just access to the module 😊
    And there they can’t MESS WITH MY TEMPLATES !!

    Hi Victor,

    Nice example. Thanks for that. I’m starting to see now how it could be useful. Thanks all for the help and knowledge imparted here!! 😊

    Best wishes,

    Mark

  • #23 / Nov 21, 2007 6:01pm

    Ryan M.

    1511 posts

    Actually, Victor, no, that conditional example won’t work.

    Right. Not to get this thread off-topic….but yeah Victor, you have to put the entire entries block in the conditionals. Believe me, I’ve been down this road. So I can get some heavily bloated templates because sometimes all I need to do is change the status parameter - but I have to have the whole entries loop there twice. Or embedded and passing stuff to it. Thought this might help me get a status in there quickly so I only need one entries block.

    Anyway, thanks again Derek, this will come in handy for small repeating bits of stuff. Not to mention those things small enough that a client might want to update that don’t really deserve an entry in a Miscelleaneous weblog or revisions.

    Mark, another use I’ve had for something like this is a link to a third party site. One client had this 3rd party link sprinkled throughout their site. When they stopped partnering with that third party and switched the link - we switched in one place. At the time it was a global variable, but it could easily be a Fresh Variable now. The 3rd party link as global var was sort of the only reason I gave that client access to the template area.

  • #24 / Nov 21, 2007 6:03pm

    Visiluna

    92 posts

    I plan to use it for date formatting as follows.

    I frequently need to display date/time in the fairly common format of

    2007-11-21 3:41:15 PM.

    This requires the following tag

    {date format="%Y-%m-%d %h:%i:%s %A"}

    Easy enough.

    However, crazy though it may seem, I do not have most of the date formatting options committed to memory, and likely never will (there are currently 31 to choose from). Therefore, every time I need to populate the “format=” parameter in the {date} tag, it requires a trip to the documentation to find the codes I need.

    The solution? Date formatting constants like {DATE_ATOM}. But wait, there is no date formatting constant equivalent to the format I need.

    I can’t make the formatting code a Global Template Variable because it isn’t parsed early enough to be interpreted correctly. I could add the date format as a variable in the path.php file. However I would like to allow a high-level (but not SuperAdmin) administrator the ability to modify this date format if needed without giving them access to the templates or the path.php file. (Yes, I’m a control freak).

    That’s where Fresh Variables comes in. I can assign “%Y-%m-%d %h:%i:%s %A” to a nice variable called {DATE_MYWAY}. My {date} tags can now become {date format="{DATE_MYWAY}”} and I suddenly start to giggle like a little girl. I can now use this in 30 templates and if the format ever needs to be changed, change it only once. (Or better yet, allow a lesser minion to do it without worry that they are going to break a template).

    Another immediate use I have is this:

    One of my clients manages a retail complex. The available retail square footage is displayed in several places around the site. However, the square footage changes on a regular basis. Up to now, I’ve had to update this manually in at least eight templates every time it changes. And I have to do it myself. Now I can give my client access to change a {AVAIL_SQUARE_FOOTAGE} variable and it automatically updates across the site with no intervention from me.

    Woohoo!

  • #25 / Nov 21, 2007 6:12pm

    Mark Bowen

    12637 posts

    Okay now I really am behind!! 😊

    Seems like everyone has a use for this somewhere!! 😊

    Will definitely look into my work-flow a bit more from now on although I do try to separate content from template code as much as possible so most things are in entry fields which brings me to a question…

    …would it be possible to somehow use these variables within entries so that in a field you could have say :

    This is just some text in an entry in a custom field and I would like to say {hello-message}.

    and it would get parsed on the page as :

    This is just some text in an entry in a custom field and I would like to say hello to all people reading this.

    This could become very handy. Is there a way to parse variables from an entry? Actually I just did a search as I thought I remembered about someone creating a way or a plug-in to do this but I can’t find the post again now. Any help would be greatly appreciated.

    Thanks.

    Best wishes,

    Mark

  • #26 / Nov 21, 2007 6:20pm

    Derek Jones

    7561 posts

    No, that would require a plugin or an extension, Mark.  Fresh Variables are parsed at the same time as path.php global variables.  As I mentioned to Victor, an easy way to see what’s happening when is to turn on the Template Parsing Log in a simple template with just a tag or two, and a few of your Fresh Variables.

    User-defined Template Variables, however, can handle what you want (see the parsing log to see where they are parsed to understand which to use and why).

  • #27 / Nov 22, 2007 2:35am

    Rob Quigley

    236 posts

    Question: what’s better for a website speed/processing - an embedded template on every page (navigation) that has dynamic code or a “fresh variable” with the same code?

  • #28 / Nov 22, 2007 9:26am

    Derek Jones

    7561 posts

    Rob Q: Though a Fresh Variable could handle it, there are very few situations I could imagine where I would choose that over an embedded template for that task.  The performance difference is negligible.

  • #29 / Nov 22, 2007 10:43am

    sigork

    155 posts

    I think instructions.html:

    Step 3
    Make sure that Extensions are enabled in ExpressionEngine by ...

    Step 4
    Go into the Modules section ...

    should be corrected.

    The Module first (Step 3), then the Extension (Step 4)

    Error
    To install the Fresh Variables extension, you must install the module.

    EDITED:

    They are in the correct order.

    Yes, you are absolutely right! Thanks a lot!

  • #30 / Nov 22, 2007 10:50am

    Derek Jones

    7561 posts

    They are in the correct order.  The rest of step 3 reads:

    If the button on the top right reads “Enable Extensions?”, click it to enable Extensions in this installation.

    Step three is just to make sure that Extensions are enabled on your installation.  Not to enable the Fresh Variables extension itself.  From step 4:

    The companion extension will automatically be installed and uninstalled along with the module from the Modules section.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases