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.

variable inside of ee tags

May 19, 2008 3:36pm

Subscribe [2]
  • #1 / May 19, 2008 3:36pm

    Silencio

    46 posts

    I’m trying to get variables (ee and/or php) inside of ee tags and having no luck.

    Example 1:

    {assign_variable:wsn_body='{weblog_short_name}_body'}
    
    {exp:weblog:entries  limit="1" disable="member_data|trackbacks"}
        {wsn_body}
    {/exp}

    Example 2:

    <?php
    $wsn_images='{weblog_short_name}_images';
    ?>
    
    {exp:weblog:entries  limit="1" disable="member_data|trackbacks"}
        {<?=$wsn_images?>}
            <a href="http://{file_url}">{file_url}</a>
        {/<?=$wsn_images?>}
    {/exp}

    These will only print out the variable text, and not associate them with custom weblog fields.

    Does anyone have a suggestion?

  • #2 / May 19, 2008 4:30pm

    Ingmar

    29245 posts

    You have to keep parse order in mind. Let’s take a look at both of your examples:

    1) You cannot use {assign_variable] dynamically. Such dynamically assigned global variables are assigned just before the processing of most other EE tags starts—but are only evaluated once. In many cases you are better off using PHP, either on Input or Output, your decision.

    2) You need to decide whether to process PHP before other EE tags, or vice versa. You cannot mix that, however.

  • #3 / May 19, 2008 4:52pm

    Silencio

    46 posts

    Thanks for responding. I switched the page to php input and did the following, still with no success.

    {exp:weblog:entries  limit="1" disable="member_data|trackbacks"}
        <?php $wsn_body='{weblog_short_name}_body'; echo '{'.$wsn_body.'}'; ?>
    {/exp}

    It just shows up as: {hr_body}, instead of printing the field.

  • #4 / May 19, 2008 5:37pm

    Ingmar

    29245 posts

    PHP on input simply means that all PHP tags are parsed before all EE tags. Problem is PHP never gets to see the value of {weblog_short_name}, because EE would have to parse {exp:weblog:entries} first, but only does so after PHP has run its course. I’m sorry, you can’t mix tags like that in this case.

    It’s very confusing, I know.

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

ExpressionEngine News!

#eecms, #events, #releases