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.

Conditional on Preload Replace

August 25, 2011 12:05pm

Subscribe [3]
  • #1 / Aug 25, 2011 12:05pm

    EyelightInc

    19 posts

    Can one use conditional statements on preload_replace variables?

    Example:

    {preload_replace:author_blog_description="<?=$qry->row('author_blog_description')?>"}
    
    {if author_blog_description!=""}
      set {author_blog_description}
    {if:else}
      not set {author_blog_description}
    {/if}

    When this runs I’m getting:

    not set blog description

    I realize I can use PHP throughout the whole template but would prefer to use EE tags if possible.

    Thanks,

    Anson

  • #2 / Aug 25, 2011 10:04pm

    Dan Decker

    7338 posts

    EyelightInc,

    Since your reported output isn’t the whole tag {author_blog_description}, the conditional is being evaluated. I think what is throwing you off here is the order that PHP is being processed in the template. You can set the PHP parsing order on a per template basis, either input, or output. Try adjusting the PHP parsing stage for this template and see if you get the results you expect. Design-> Templates-> Template Manager, then select the template group, then edit preferences for the template in question. The default is “Output” and according to the Docs, you want “Input” since the PHP will be evaluated before EE tags, allowing PHP to affect the rendered template. Let us know if this helps

    Cheers,

  • #3 / Aug 26, 2011 9:33am

    EyelightInc

    19 posts

    Thanks Dan,

    The tag was actually outputting the value saved in the the preload_replace variable.

    I did try input and output, sorry should have mentioned that. I ended up going with an entirely different approach that is working. 

    So preload_replace variables can be conditionally checked if php is enabled and set to input?

    Anson

  • #4 / Aug 27, 2011 12:54am

    Dan Decker

    7338 posts

    Eyelightinc,

    In your example, PHP on “input” would be evaluated fisrt, and should *populate* your preload_replace before EE tags.

    Do you mind sharing the working solution you ended up with? It may help others better understand EE in the future!

    Thanks,

  • #5 / Aug 29, 2011 11:49am

    EyelightInc

    19 posts

    Sure Dan,

    I think part of my problem is there are so many different ways to solving problems in EE. Quite often my first attempt isn’t correct.

    I was simply trying to get custom fields for a member based on an authors screen name. So my alternate solution queries the database to get the member_id for the screen name. I then use custom_profile data. PHP is set to parse on input.

    <?php
    $qry = $this->EE->db->select('m_field_id_1 as author_blog_description, members.member_id')
                        ->from('exp_members')
                        ->join('exp_member_data', 'exp_members.member_id = exp_member_data.member_id')
                        ->where('exp_members.screen_name','{segment_3}')
                        ->get();
    
    
    ?>
    <aside>
              {exp:member:custom_profile_data member_id="<?=$qry->row('member_id')?>"}         
            <div class="profile">
                {if photo_url!=""}{photo_url}{/if}
                <div class="name-title">
                <h3>{segment_3}</h3>
    <p>            {if occupation}<em>{occupation}</em>{/if}<br />
                </div><br />
                <div class="contact"><br />
                    {if author_twitter}<a href="http://twitter.com/#%21/{author_twitter}" class="twitter" target="_blank" rel="noopener">Twitter</a>{/if}<br />
                    {if author_linkedin}<a href="http://{author_linkedin}" class="linkedin" target="_blank" rel="noopener">LinkedIn</a>{/if}<br />
                    {if author_facebook}<a href="http://{author_facebook}" class="facebook" target="_blank" rel="noopener">Facebook</a>{/if}<br />
                    {if author_google_plus}<a href="http://{author_google_plus}" class="googleplus" target="_blank" rel="noopener">Google+</a>{/if}<br />
                    <a >row('member_id')?>" class="email">Email</a><br />
                </div>        <br />
            </div>{/exp:member:custom_profile_data}<br />
        </aside>

    Thanks,

    Anson

  • #6 / Aug 29, 2011 12:26pm

    Sue Crocker

    26054 posts

    Thanks for sharing your solution, Anson. There certainly can be many ways of doing things with EE. If anything else comes up, please do let us know in a new thread..

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

ExpressionEngine News!

#eecms, #events, #releases