All Low add-ons are now owned by EEHarbor. Read the blog post.

Support archive

How do you enter snippets

icebreaker 16 Jan 2012 00:34 question, complete

Do you enter them in a text area. Or something else.
Not clear from the documentation.

Are the field types "EE fields" that get entered into templates as such, or are the fields available user interfaces for entering content into low variables?

Replies

  1. Low 16 Jan 2012 06:53

    Snippets are defined by their place in the parse order, not by their type. Any variable can be a snippet in that sense if you tick on enable Early Parsing for that variable. As a rule: early parsed Low Variable == Snippet.

    The var/field types are interfaces for entering the variable's value. You can use either the basic variable syntax (e.g.: {my_variable}), which will output the raw data. You can also use the template tags (e.g.: {exp:low_variable:single var="my_variable"} or {exp:low_variable:pair var="my_variable"} ... {/exp:low_variable:pair}) to output the data with more options, depending on the variable type.

  2. icebreaker 16 Jan 2012 11:16

    OK - that is more precise description on the rationale for the different variable types. Thanks for the quick reply.

  3. JimmyFurtado 18 Jan 2012 16:46

    From my testing, it seems like early parsed Low Variables get parsed before Snippets, which can come in handy occasionally as adds another option to embed.

    Could you confirm that my read on this is accurate?

    Thanks.

  4. Low 18 Jan 2012 17:22

    Here's the thing: all early parsed variables, including snippets, are added to the "Snippets" array. If you turn on Template debugging, you can see the keys and values of this array. The array is populated by EE at different stages, with different content. The native snippets are loaded into it early on, and it can get values added to it by add-ons, like Low Variables, using extension hooks.

    In the template parser, all the items in the Snippets array are parsed in the order that you can see in the template debugging info. If native snippets are there before early parsed LV, then yes, that's accurate. However, I'd recommend not to rely on this particular order, as things might change.

  5. JimmyFurtado 30 Jan 2012 18:34

    I have a follow-up question. I have a snippet that I created for a sidebar for a few things including a Solspace Template Morsel (TM). If I put the EE code into an EE Snippet it works fine. If I change it to an early parsing Low Variable (eLV), the TM does not display correctly.

    eLV {ignored_blogs} equals "not about|membersonly|gamechatter|jf|news" (without the quotes).

    This {exp:template_morsels:fetch name="hot_topics" channels="{ignored_blogs}" show="yes"} works within a Snippet. It doesn't work if I copy and paste the markup with a eLV.

    This {exp:template_morsels:fetch name="hot_topics" channels="not about|membersonly|gamechatter|jf|news" show="yes"} works within the eLV.

    Additionally, the TM will parse segment variables within a eLV. So, {exp:template_morsels:fetch name="hot_topics" channels="{segment_1}" show="yes"} works fine within a eLV.

    Here is what is placed within the TM:

    <div class="sidetitle_red"> 
    <h3>Hot Topics</h3>
    {exp:bbtf_hot_topics:display channel="{channels}" show="{show}" limit="15" format="%g:%i%a, %M %d"}
    </div>


    Why doesn't EE parse the TM within my Low Variable?

  6. Low 30 Jan 2012 18:50

    So, let me get this straight. You have a snippet or eLV that contains an exp-tag (the template morsel code) and at least one other eLV? Is that right?

  7. JimmyFurtado 30 Jan 2012 19:06

    Here is the full code with that works when placed with an EE Snippet

     
    <!-- Begin Right Column -->

    {exp:template_morsels:fetch name="rightcol_adblock"}

    <!--Begin Bookmarks-->
    <div class="sidetitle_red">
    {if logged_in}
    {embed="global_templates/bookmarks"}
    {/if}
    {if logged_out}
    <h3>Bookmarks</h3>
    <p> You must be logged in to view your Bookmarks.</p>
    {/if}
    </div>
    <!--End Bookmarks-->

    {exp:template_morsels:fetch name="hot_topics" channels="{ignored_blogs}" show="yes"}

    {if segment_2 == 'discussion'}
    {ad_left_column_leaderboard}
    {/if}

    <!-- End Right Column -->


    {ignored_blogs} is also an early parsed Low Variable.

    After more testing, I find that if I place either {ignored_blogs} or {channels} (which is what {ignored_blogs} gets passed as into the Template Morsel), the correct value of {ignored_blogs} appears correctly (not about|membersonly|gamechatter|jf|news).

    So, {ignored_blogs} is getting passed into the Template Morsel but for some reason is not getting used within the exp:template_morsels tag.

  8. Low 30 Jan 2012 21:47

    Okay, brace yourself. :)

    Both native Snippets and early parsed Low Variables (eLV) are early parsed variables (EPV). According to EE's parse order, they're the first things parsed in a template.

    From a technical point of view, the EPV are stored internally in a single array (if you're PHP savvy) or stack. That array is then processed one item at a time. Take a look at my presentation slides Parse Order Pro, slides #11 to #24. There you can see that the order of the items in the stack matters. Before the EPV are parsed, the stack is populated at different stages, which influences their order in the stack.

    First, any variables defined in your index.php or config.php file are added to the stack. Then any variables set by add-ons (extensions) using the session_start or session_end hooks (like Low Variables or Low Seg2Cat does). After that, the native Snippets are added to the stack, but any existing EPV in the stack are replaced in the Snippets first.

    So, the reason why it works when you put the code in a Snippet is this:
    - The eLV are added to the stack
    - Snippets are loaded and existing EPV (including eLV) are replaced inside them
    - Prepared Snippets are added to the stack
    - Template is parsed as per the linked pdf

    When you add one eLV into another, it might lead to unexpected results, as the order of the eLV in the EPV stack is unpredictable.

    Hope that explains it a bit.

  9. JimmyFurtado 31 Jan 2012 01:48

    I spent a little time going through the template code and doing some of my own tests before reading your well-explained note. It seems to make sense for me to do the following:
    1) Place variables I want available everywhere in the site's index.php global_var array (True Global Variables);
    2) Put other variables that I'd like to parse early in LV (for simple conditionals, use in Snippets, etc.) and set them to parse early. (Early Global Variables)
    3) Place my larger code stuff for entry tags and sidebars into EE's Snippets so that I can embed LV early variables with them. (Snippets)
    4) Place non-parsing variable stuff (footers, Google Analytics, etc.) in LV and set them to parse late. (Late Global Variables)

    Any chance that you can add the ability to control index.php variables and snippets within LV? To me that would give designers/developers quite a few weapons in their arsenals.:D

    Thanks for such a great module and for taking the time to thoroughly explain the ins and outs of using it.

  10. Low 31 Jan 2012 15:25

    I'm afraid editing the index.php vars is not an option. The file would have to be writable, which isn't recommended. Also, vars set in the index.php would mostly be environment dependent.

    I try to make LV the alternative for not having to use native snippets or late GV. Most should be possible with just LV and the three parse stages. For example, you could add this to an eLV:

    <!-- template data --> 
    {exp:low_variables:pair}
    {exp:template_morsels:fetch name="hot_topics" channels="{ignored_blogs}" show="yes"}
    {/exp:low_variables:pair}
    <!-- more template data -->


    ...where {ignored_blogs} can be either early or late parsed. Wrapping the var around the parameter-less {exp:low_variables:pair} tag will parse the var then and there, in time for the {exp:template_morsels:fetch} tag to use it.

  11. JimmyFurtado 1 Feb 2012 22:03

    I can understand the problem with using the index.php file. I also appreciate that I can accomplish the same functionality by using the pair tag. Why not manage snippets from within Low Variables, though? The additional feature would add more value to your already impressive module.

    I will take another look at the parsing options with the LV tags.

    Thanks again for taking the time.

  12. Low 3 Feb 2012 12:22

    I guess in most cases, eLV are equal enough to snippets not to matter. An option would be to store eLV in the native Snippets table and late parsed Low Variables (lLV) in the native Global Variables table (as all the LV are at the moment). However, this would require quite a significant rewrite of the module's code.

    If you want more control over which eLV are parsed first, or in what sequence, I might actually prefer adding them to the stack in the order they are presented in the CP. That might actually be helpful already and wouldn't take much effort.

  13. JimmyFurtado 3 Feb 2012 13:44

    I love the idea of being able to order Low Variables. It would allow me to embed eLV within other eLV. I also could order them by function and set customization eLV variables (like {lve_channels_homepage} = "channel1|channel2|channel3") at the early point in the parsing cycle and use those variables in eLV code snippets (Low Snippets). Such a setup would make it much easier for me manage my variables.

    Because I'd be able to set the sort order, I'd be able to display my variables with a clear ordering by use:
    1 {elv_channels_homepage}
    2 {elv_channels_archive}
    3 {lsn_entries}
    4 {lsn_comments}
    5 {lv_footer}
    6 {lv_footer_homepage}

    So, after thinking about it for a few minutes, I would prefer having the ability to order Low Variables because my variable management would be all in one place *and* I'd have much more fine-tuned control of when they get called.

  14. Low 6 Feb 2012 08:11

    I'll see if I can add this to the next version. However, it will only be applied to eLV. The late parsed vars are handled by EE itself, so I have no control over how they are fetched from the DB.