0

I am building a plugin that takes variables from the url's query string and renders out the appropriate category ids, but when I tried testing out a category that I know exists and place the plugin tag inside the category parameters.

{exp:channel:entries channel="products" category="{exp:test_plugin}"}
   {title}
{/exp:channel:entries}

It outputs some hash:

{exp:channel:entries channel="product" category="M00o93H7pQ09L8X1t49cHY01Z5j4TT91fGfr" dynamic="no"}

But when I place the plugin tag outside of the category parameter it prints out the number. Here's my plugin so far.

class test_plugin {
   public $return_data = "";
   public $c;
   public $s;
   public $m;
   public $t;

public function __construct($tagdata = NULL){
    $this->return_data = 28;
}



function type_name(){
    return $this->t;    
}

public function usage()
{
    ob_start();
    ?>
        :)

    <?php
    $buffer = ob_get_contents();

    ob_end_clean();

    return $buffer;
}
}

How would I get it to print out the actual category number?

3 Answers 3

1

This just happens in really trick situations. You probably have more than one instance of the same tag on different parsing levels: one inside another tag and other one outside all of them.

The template parser replaces all the instances of the plugin with the placeholder M00o93H7pQ09L8X1t49cHY01Z5j4TT91fGfr, to avoid run it over and over again, and then, because they are at different levels, it tries to parse the exp:channel:entries before to replace the placeholder back.

You can remove the different instance you're probably using for testing. If this isn't an option, add a false parameter to the instance inside the exp:channel:entries opening tag.

{exp:channel:entries channel="products" category="{exp:test_plugin random}" parse="inward"}

This will make the two instances to be different, so they will not be replaced by a placeholder and your plugin will run again.

3
  • Is there are way for me to force it not to create that placeholder? Oct 8, 2014 at 17:58
  • No, but the sample code I sent should work. Is your plugin working outside other tags?
    – Sobral
    Oct 8, 2014 at 18:20
  • Yes the code you gave me works and the outside tag works as well. Oct 8, 2014 at 18:28
1

Scrap it. I suggest using Low's Seg2Cat. Tried and True. Gives a ton of other variables too that you can use throughout your templates.

3
  • Was going to use that plugin but needed to format my url like www.example.com/products/filters?t=Rings&s=24_40_30&metal=33_34_45&s=34 Oct 8, 2014 at 17:22
  • Where is the category in that URL, Rings, Metal? If you so, you could use Mo' Variable too which could pass the correct query string to Low's plugin
    – Siebird
    Oct 8, 2014 at 17:25
  • Well the product type is the t variable and the other variables are sub categories that are the exact ids of each selected metal and stone types that can be selected. Oct 8, 2014 at 17:27
0

I think maybe it's an parse order issue.

{exp:channel:entries channel="products" category="{exp:test_plugin}" parse="inward"}

See the docs: https://ellislab.com/expressionengine/user-guide/templates/plugins.html#changing-parsing-order

1
  • Still rendering as that hash string Oct 8, 2014 at 17:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.