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

Support archive

Newbie - using Low Variables instead of snippets and other basic use questions

L2 17 Jan 2012 17:25 question, complete

I'm trying to get a better handle on how I should be using Low Variables when it comes to Snippet functionality and basic usage. I'm sorry if these are really basic questions. I did my best to watch LV tutorials, listen to EE Podcasts about LV, read others experiences with LV, the forum, etc. but I'm still a bit confused on some basic usage.

It's my understanding that I can Low Variables in place of Snippets (and Global Variables which I've never used natively). Although I'm using EE2, I started on EE1 and therefore still use Embeds for my reusable code like main navigation, sidebars, etc. I am attracted to Low Variables because I can save the variables as files and edit locally plus it sounded like LV processes faster than if I put the reusable code in an embed.

I attached a screen shot of where I am currently using Embeds. These embeds are just reusable code that is shared amongst all (or many) other pages.



My questions:
1. Would I would simply replace my embed code in the template with Low Variables code? I tried this using the variable name {lv_footer} and it seems to work fine. Are there any embeds that I currently have that would stay as embeds like "html-header" which contains my css, js, etc.?

2. Normally I would just have a file for each specific type of code replacement (main nav, sidebar, etc.), however I still have the top part of the HTML repeated on all or most pages (like doctype, headerWrapper, etc. as shown in my screenshot). Do most people create an embed or LV for this info or leave it hardcoded in the page as I have shown here?

3. I have multiple sidebar elements that I currently have saved as separate embeds (would make these separate LV). I like to have them separate because it's easier to edit and understand the code. However, does that take more template processing load time because I'm loading multiple LVs versus having them all in one sidebar LV?

3. Is there a rule of thumb to know when a LV needs to be parsed early?

4. How do you know which templates tags to use with LV as shown on the http://gotolow.com/addons/low-variabl... page? Single versus pair versus parse, etc.

Thanks so much for your help!

Lori

Replies

  1. Low 17 Jan 2012 17:42

    Hi Lori,

    1. Yes. Copy the content of your embed into a LV textarea, enable early parsing, and you're good to go.

    2. You could do both. Performance-wise it makes little difference.

    3. Having multiple embeds is *way* more heavy on the template parser than having multiple snippets/LVs. Basically, the amount of snippets in a template hardly makes a difference in performance (depending on what's in those snippets, of course).

    4. If your LV contains *any* EE tags, or if you need to use the variable itself as a conditional (e.g.: {if lv_variable_name == 'foo'}) then you need to enable early parsing.

    5. For most variables, you can use the basic variable syntax, without using the template tags, e.g.: {lv_variable_name}
    For certain variable types, you can customize the output. Then you'll have to use either the {exp:low_variables:single} or {exp:low_variables:pair} tags.

  2. L2 17 Jan 2012 18:04

    Thank you so much for the quick and thorough response Low. I really appreciate it.

    One more question about saving the variables as files. Is it okay to save them to a folder in the system? I wanted the LV folder "template_low_variable" to appear above my normal template folder so it was easier for me to jump back and forth locally.

    Lori

    Low 19 Jan 2012 08:19

    Oh and yes, you can define any folder you want to save the vars. Above or below web root doesn't matter.

    L2 19 Jan 2012 12:55

    Great, thanks! I'm loving Low Variables and I know I just scratched the surface. Replacing embeds with LV has sped up my templates considerably. Plus using them has saved on my development time too. Thanks for creating such a robust add-on and for your fantastic support.

    Lori

  3. Euan 18 Jan 2012 12:06

    Sorry for adding to this thread but I am much in the same position as L2 and I felt it made more sense to add a question here instead of creating a new newbie thread.

    Can you put LV's within LV's? I ask this as my site I am working on will be membership based with different content available to different member groups and I wondered if it would be sensible to place the content aspects within LVs.

    For example...

    {if logged_in}
    {if member_group == 'X'}
    Yes you're a paid member and can view this.
    {if:else}
    Sorry, you need to pay to view this.
    {/if}
    {if:else}
    Sorry, you need to join to view this.
    {/if}


    The above code would be a LV but X (or the whole member_group section) would be a separate LV. This would allow me to control access to specific content across the site. Also using a separate LV for the 'Sorry you need to pay code', etc.

    So that the code would be..

    {if logged_in}
    {if {LV_member_access}}
    Yes you're a paid member and can view this.
    {if:else}
    {LV_you_need_to_pay}
    {/if}
    {if:else}
    {LV_you_need_to_join}
    {/if}


    Does this make sense?

    Thanks
    Euan

  4. Low 18 Jan 2012 12:22

    Hi Euan,

    First, take a look at this pdf. You'll need to know this:

    A) LVs with early parsing enabled are parsed at stage #1
    B) LVs parsed using {exp:low_variables:...} tags are parsed at stage #5
    C) LVs with early parsing *disabled* are parsed at stage #9

    You can put late parsed vars in early parsed vars but not vice versa. So:

    B in A = ok
    C in A = ok
    C in B = ok

    ...all other permutations can lead to unexpected results.

    In your example, the complete code block could be an A (parsed early). The LV_you_need... vars should be C (parsed late). The tricky bit is the conditional statement. It should be an early var, but putting an A inside another A won't work in all cases. So you'll have to make that one a B. Something like this:

    {if logged_in} 
    {if member_group == '{exp:low_variables:single var="LV_member_access"}'}
    {LV_ok}
    {if:else}
    {LV_pay_up}
    {/if}
    {/if}
    {if logged_out}
    {LV_login_please}
    {/if}

  5. Euan 18 Jan 2012 13:43

    Low,

    Thanks for the prompt response.

    Would it be simpler to just do the following and have the entire bit parse early?


    {if logged_in}
    {if member_group == 'X'}
    {LV_ok}
    {if:else}
    {LV_pay_up}
    {/if}
    {/if}
    {if logged_out}
    {LV_login_please}
    {/if}


    For the LV_ok, LV_pay_up and LV_login_please - would these be set to parse early?

    Sorry for the questions - I only do this as a hobby so I have no knowledge of how this all works!

    Euan

  6. Low 18 Jan 2012 14:26

    Would it be simpler to just do the following and have the entire bit parse early?


    Yeah, that would work.

    For the LV_ok, LV_pay_up and LV_login_please - would these be set to parse early?


    No, you don't need to enable early parsing for these variables.

  7. Euan 18 Jan 2012 15:15

    Thanks for the prompt responses.

    Will be ordering soon as I like the idea of being able to put text blurbs into variables which makes it easier for me to manage the site going forward.

  8. JimmyFurtado 18 Jan 2012 15:50

    I was just looking for the advanced parsing information. I had created a late parsing variable for Google Analytic Code to embed into another late parsing variable for the footer. Thanks to your description above, I quickly figured out my problem.

    It may be a good idea to move your example about into an FAQ about the module.

    Low 20 Jan 2012 10:07

    Good point, Jimmy. I might well do exactly that.

  9. Euan 22 Jan 2012 17:35

    Sorry to keep asking questions.

    I've been setting up some variables but I am having problems getting content from my entries to appear and I am not sure if I've set it up and used the correct template tags.

    My Low Variable is call {lv_advanced_guide_content}

    {if logged_in}
    {if member_group == '1'}
    {articles_content}
    {if:else}
    {articles_excerpt}
    {lv_you_need_to_pay}
    {/if}
    {/if}
    {if logged_out}
    {articles_excerpt}
    {lv_join_or_login_to_access}
    {/if}


    In my channel that I want to pull content from I have {articles_content} and {articles_excerpt} as the two fields.

    In my template, I have the following code

    {exp:channel:entries channel="articles" custom_fields="on" member_data="on" limit="1" track_views="one"}
    <h2>{title}</h2>
    <div class="articles">
    {exp:low_variables:parse var="lv_advanced_guide_content"}
    ...


    However, when I go to view the template, instead of the content being shown from either of the entry fields, it is just displaying the field tag i.e. {articles_content} or {articles_excerpt}

  10. JimmyFurtado 22 Jan 2012 17:44

    I am not Low but...you might want to make lv_advanced_guide_content an early parsing Low Variable and display it as:
    {lv_advanced_guide_content}
    I believe using the parse tag means it gets parsed at the same time that EE tags are parsed, rather than earlier in the order like an early parsed Low Variable.

    Posted in case Low isn't around and this might help you.

    Euan 22 Jan 2012 17:56

    Jimmy, thanks for responding.

    {lv_advanced_guide_content} is already set to early parsing.

  11. Low 22 Jan 2012 18:07

    Euan, Jimmy is right. You'll need to replace the {exp:low_variables:parse var="lv_advanced_guide_content"} tag with the simple {lv_advanced_guide_content} variable. Then you should be fine.

  12. Euan 22 Jan 2012 18:13

    Low / Jimmy

    Thanks for your help - I didn't appreciate I just had to put {lv_advanced_guide_content} by itself!

    Working perfectly.

    Thanks,
    Euan