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.

URL title {url_title} won't work in Snippet

October 17, 2012 5:08am

Subscribe [1]
  • #1 / Oct 17, 2012 5:08am

    Wayne Smallman

    176 posts

    Hi guys!

    <?php
     $product_video = '{embed:product_video}';
     $product_video_title = '{embed:product_video_title}';
    
     if (isset($product_video_title) && isset($product_video)): ?>
    <a href="http://&lt?php" title="<?php echo $product_video_title; ?>" class="youtube">{site_url}uploads/videos/trachi-naze.jpg</a>
    Play <strong><a href="http://&lt?php" title="<?php echo $product_video_title; ?>" class="youtube"><?php echo $product_video_title; ?></strong></a> Video
    <?php
     endif; ?>

    All of which works fine as a Snippet.

    But the moment I try using {url_title} in there, {url_title} is written out literally, rather than rendering it as the URL title to which Entry the Snippet is embedded into.

    I’ve even tried doing the Embed-to-PHP switch (as above), but that didn’t work either.

    Any ideas?

  • #2 / Oct 17, 2012 6:22am

    Wayne Smallman

    176 posts

    Guys, just so you know, this came about as a result of me not adding an Embed into the Template at source.

    All working fine now.

  • #3 / Oct 17, 2012 12:37pm

    Dan Decker

    7338 posts

    Hi Wayne,

    I’m glad you were able to sort out the issue.

    That’s an good bit of PHP in your template. It would be worth looking at getting that into a plug-in or a way to do the same work with ExpressionEngine tags. You would see a nice performance improvement.

    Cheers,

  • #4 / Oct 17, 2012 2:35pm

    Wayne Smallman

    176 posts

    Dan, thanks.

    I thought it quite basic code, given what it’s attempting to accomplish.

    Here’s the final code, which sifts through a multidimensional array, to determine where a video should be displayed, taking into account Entry hierarchy…

    <?php
     $url_title = '{embed:url_title}';
     $product_video = '{embed:product_video}';
     $product_video_title = '{embed:product_video_title}';
    
     $array = array(
      'trachi-naze' => array('the-system', 'baseplates', 'clinical-results')
     ); // end array
    
     function find_in_array ($array, $query) {
      foreach($array as $key => $value) {
          if(in_array($query, $value)) return $key;
      }
     }
    
     $key = false;
    
     $key = find_in_array ($array, $url_title);
    
     if (isset($key)):
      $url_title = $key;
     endif;
    
     if (isset($product_video_title) && isset($product_video)): ?>
    <a href="http://&lt?php" title="<?php echo $product_video_title; ?>" class="youtube">{site_url}uploads/videos/<?php echo $url_title; ?>.jpg</a>
    Play <strong><a href="http://&lt?php" title="<?php echo $product_video_title; ?>" class="youtube"><?php echo $product_video_title; ?></strong></a> Video
    <?php
     endif; ?>
  • #5 / Oct 18, 2012 2:33pm

    Dan Decker

    7338 posts

    Hi Wayne,

    Thanks for sharing!

    I thought it quite basic code, given what it’s attempting to accomplish.

    Oh, that’s not where the impact comes from. It’s how ExpressionEngine has to process PHP in templates that is a performance concern.

    So, EE has to parse out your PHP from the template, which itself is being rendered out with PHP. Once EE parses out your PHP code, it then runs it through eval() and returns the result back to the template engine.

    The ultimate goal is for you to have a solution that works for you and that you are satisfied with.

    Is there anything else I can assist you with?

    Cheers,

  • #6 / Oct 18, 2012 3:19pm

    Wayne Smallman

    176 posts

    Hi Dan, I’ve had a look at Add-On development, but it’s something I’ll have to return to when I have more time. But I do appreciate your point.

    As for the offer of help, a good Add-On development how-to article or two wouldn’t go amiss!

  • #7 / Oct 19, 2012 4:20pm

    Dan Decker

    7338 posts

    Hi Wayne,

    Absolutely! Our own Wes Baker has a tutorial on building a plug-in and Blake Walters just spoke at EECI on plug-ins.

    Best of luck!

    If you need anything else, just let us know!

    Cheers,

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

ExpressionEngine News!

#eecms, #events, #releases