• Resolved jsndvn

    (@jsndvn)


    Hey

    I’m struggling to find a way to pass PHP variables like $alm_item to my default template, which I’ve set up using get_template_part() and some conditionals checking for certain choices in the customizer, like so:

    <?php
    
    if (get_theme_mod( 'zendroidcore-archive-post-layout' ) == 'value1' ) 
    
    	{ get_template_part('partials/side-by-side-ajax', 'snippet' );  } 
    
    elseif (get_theme_mod('zendroidcore-archive-post-layout') == 'value2' ) 
    
    	{  get_template_part('partials/over-and-under-ajax', 'snippet' ); }
    
    elseif (get_theme_mod('zendroidcore-archive-post-layout') == 'value3' ) 
    
    	{  get_template_part('partials/masonry-ajax', 'snippet' ); } 
    
    else {}
    
    ?>

    They just throw an undefined variable error. I tried setting them to global at the top of the template but that didn’t have any effect, and also tried passing them using a Session and that didn’t help either.

    All I’m trying to do is get a count of each post in the ALM loop so I can style the first one individually (it’s going to need different markup structure to achieve what I need to do so CSS nth-of-type or anything like it won’t work here).

    I’d be very grateful for a pointer on what I’m doing wrong with it! Otherwise I’ve had a flawless experience with the plugin, it’s superb and I’ll definitely be upgrading to paid addons as soon as I can.

    Thanks,

    Jason

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter jsndvn

    (@jsndvn)

    After some careful reading of the docs on your site I found that if, instead of using get_template_part, I just expand the snippets into a default.php repeater template and put it into an alm_templates folder in the theme root, I’m able to make use of those variables. But I don’t quite get why they’re not available when loading partials, which I’d prefer to do for the sake of keeping things tidier.

    Plugin Author Darren Cooney

    (@dcooney)

    For whatever reason variables don’t get passed to get_template_part() – not just ALM variables.

    You can use include(locate_template('includes/{your-template}.php'));

    Cheers,

    • This reply was modified 6 years, 11 months ago by Darren Cooney.
    Thread Starter jsndvn

    (@jsndvn)

    Well isn’t that weird.

    Thanks very much for the quick solution. I’ll go back to calling the partials using that and keep things as modular as possible, and I guess all I need to do is work out the path.

    Cheers man

    P.S. I wanted to ask you about extended licensing for inclusion with a theme, can I get in touch on Twitter?

    Plugin Author Darren Cooney

    (@dcooney)

    No problem and sure, Twitter is fine.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘ALM variables are undefined when using get_template_part() method’ is closed to new replies.