7

So I'm taking an existing site and cloning it to use for another site. The thing is the existing site was built a long time ago and has several template insufficiencies including embeds nested 3 levels deep which I would like to fix.

So I've got the header embed now as a low variable which is great. However there are two further embeds within the header that I would like to use as separate low variables just to keep things easy to see in the templates - each of these is a rather large chunk of code.

I've read Low Variables 2.3 totally killed the embed tag and see how that works, however I'm not really passing variables through to the first low variable.

My question is can I do what I want to and if so are there any implications for the future or speed of the site.

exisiting code sample here

<header id="header">
    <div class="header-bar">

 A whole bunch of code

        {embed="embeds/_booking-box"}
    </div><!--header-bar-->

More code here

<!-- navigation -->
    {embed="embeds/_nav"}
</header>

So in the new template I want to replace those embeds with other low variables - do I need to preparse or not and will it work?

13

Preparse vars are best used for simple bits of data, not large chunks of code. This is because the Preparse vars are passed along to the variable content by means of a parameter, and large amounts of data (with line breaks, etc...) inside a parameter is never a good idea.

Looking at your example, there aren't any embed variables being passed through the embedded templates. That's a hint that you probably don't need Preparse variables either.

Instead, I'd recommend you create a LV group where you store early parsed template code snippets. Let's call that group 'Snippets'. Inside the group, you add 3 early parsed vars. The first one is the header var, which contains the booking-box and nav vars. All 3 should be early parsed, and the header var should be above the other two, so it gets parsed before them. Then all 3 should be parsed just fine.

In conclusion, create 3 early parsed textarea vars in a group in this order, eg.:

  • lv_snippet_header
  • lv_snippet_booking-box
  • lv_snippet_nav

Then in the lv_snippet_header, add this:

<header id="header">
  <div class="header-bar">
    A whole bunch of code
    {lv_snippet_booking-box}
  </div><!--header-bar-->

  More code here

  <!-- navigation -->
  {lv_snippet_nav}
</header>

And then add the above var to your templates in the variable syntax: {lv_snippet_header}

If you're using the tag syntax: {exp:low_variables:single var="lv_snippet_header"} then you need to change the reference to the variables inside it to use tag syntax as well and you can then disable early parsing, as that's irrelevant for tag syntax.

  • Always a lifesaver @Low! – Dan Mar 16 '13 at 9:28
6

Taken straight from Low

Nesting early parsed vars is tricky business. Before the version 2.0.3, there was no predefined order in which the early parsed Low Variables (EPLV) were dealt with, so basically, if it worked, then that's just lucky. :)

As of LV 2.0.3, the EPLV are added to the native Snippets array (and thus parsed) in the order they appear in their group (actually, first by group ID, then by order in the group). This means you have more control over which EPLV are parsed before others.

In your example, you could have a group called Snippets, containing 3 EPLV, say {sidebar}, {sidebar_content_1} and {sidebar_content_2}. If you want to put the latter two in the first one, you'll have to make sure the order of the vars in the group is this:

  • sidebar
  • sidebar_content_1
  • sidebar_content_2

Then it will work. An order like this will not work:

  • sidebar_content_1
  • sidebar_content_2
  • sidebar

If you're nesting variables across groups, I'd recommend putting them in the same group to have more control over the order in which the EPLV are parsed.

Hope that helps.

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.