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.

Passing variables to embedded templates

April 27, 2008 10:27pm

Subscribe [3]
  • #1 / Apr 27, 2008 10:27pm

    seajay

    109 posts

    This is related to http://ellislab.com/forums/viewthread/4076/

    I am working to modularize my project by moving common template elements to embedded templates.

    However, I’m having trouble understanding how to pass variables to the embedded templates.

    For example, I wish to pass {entry_date}. I’ve tried

    {embed="content-blocks/date" pass_entry_date="{entry_date}"}

    Then in content-blocks/date, I have:

    {{embed:pass_entry_date} format='%l %M %d  %Y'}

    However, I am getting:

    {1209280680 format=' %l %M %d %Y'}

    What am I doing wrong? Are there any threads that go into more detail about passing variables?

  • #2 / Apr 28, 2008 3:28am

    Ingmar

    29245 posts

    Try this:

    {embed:pass_entry_date format="%l %M %d  %Y"}
  • #3 / Apr 28, 2008 9:58am

    seajay

    109 posts

    Hmmm.

    The containing template:

    {exp:weblog:entries weblog="{embed:current_weblog}" limit="1"} 
    {embed="content-blocks/date" current_weblog="{current_weblog}" current_template_group="{current_template_group}" pass_entry_date="{entry_date}"} 
    {/exp:weblog:entries}

    Now, I put this in the embedded template”

    {embed:pass_entry_date}
    {embed:pass_entry_date format="%l %M %d  %Y"}

    This is what I’m seeing.

    1209280680 {embed:pass_entry_date format="%l %M %d %Y"}

    The date appears to be passing (I assume that “1209280680” is the numeric date value).

    However, for some reason the format date processing isn’t happening. Do I have to turn it on somewhere?

  • #4 / Apr 28, 2008 10:19am

    seajay

    109 posts

    Correction. I discovered one problem: in multiple nested templates, one must add embed to to beginning of variables.

    So, they’re all working except ... the passed entry_date variable appears as 1209280680 but, as soon as I add formatting code, the variable breaks.

    So ...

    {embed:pass_entry_date}

    ... appears as ...

    1209280680

    However ...

    {embed:pass_entry_date format="%F %d %Y"}

    ... appears as ...

    {embed:pass_entry_date format="%F %d %Y"}

    Here’s my original note; now irrelevant.

    Additional info: none of my embed statements are being parsed.

    {current_weblog} {current_template_group} 1209280680

    I added a {exp:weblog:entries} loop around the fields and they just disappeared.

    I think I’m missing something very basic about assign variables, or configuration.

    Any ideas? Links to threads that clarify passing variables to embedded templates?

  • #5 / Apr 30, 2008 5:18pm

    Ingmar

    29245 posts

    What if you format the date in the calling template, so to speak:

    {embed="content-blocks/date" pass_entry_date="{entry_date format='%l %M %d  %Y'}"}

    And then simply {embed:entry_date} in the embed? If that fails, you can certainly use PHP to achieve what you’re after, but it seems like overkill.

  • #6 / Apr 30, 2008 5:42pm

    seajay

    109 posts

    Bingo. Thank you!

  • #7 / Apr 30, 2008 5:43pm

    Ingmar

    29245 posts

    Woot 😊 Closing for now.

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

ExpressionEngine News!

#eecms, #events, #releases