2

I want to pull a url segment variable into the pyrocms file plugin call. it would look like

{{files:listing folder="[segment(2)]"}}

or something of the sort. What is the trick for embedding

{{url:segments..}} 

inside

{{files:listing folder="…}}

I am trying to setup this up for a conditional query for a photo gallery

salmane
  • 4,799
  • 13
  • 48
  • 61
  • I want the folder to be a variable pulled from the url. so it would look like {{files:listing folder="[segment(2)]"}} or something of the sort – salmane Oct 08 '12 at 13:23

1 Answers1

1

If you take a look at the PyroCMS Tags documentation you will see this clearly documented in the "Tag Attributes" section.

You may also use the output from other tags as attribute values in your tags. For example if you wanted the url segment to default to the slug of the currently viewed page you could do this:

{{ url:segments segment="1" default=page:slug }}

Here is an example showing the proper use of quotes and braces when the tag used as the attribute value has an attribute itself.

{{ url:segments segment="1" default={foo:bar value="baz"} }}

Tip: Omit quotes and braces when using tags as attribute values. The only exception is when the tag you are using as the attribute value has its own attributes.

So you can do that easily with:

{{ files:listing folder={url:segments segment="2"} }}

Basically you don't need to pretend it's a string if it's not. You can just send the foo:bar arguments through, but it if has attributes you can "group" the attributes with the call via a single { and }.

Simple right? :)

Community
  • 1
  • 1
Phil Sturgeon
  • 30,637
  • 12
  • 78
  • 117
  • Thanks Phil. what if part of the folder is static and the rest is a varible as follows,{{ files:listing folder="galleries/".{url:segments segment="2"} }} what separators should I use? – salmane Oct 08 '12 at 16:37
  • 1
    Whenever you start trying to do complicated things with Lex think to yourself "Should this be a plugin instead?", because it probably should be. Otherwise you can do `{{ files:listing folder="galleries/{{ url:segments segment='2' }}" }}` and that should work, but you're getting into syntax soup. – Phil Sturgeon Oct 08 '12 at 17:20
  • I tried that but it didnt work, I tried every variation of it I could. To be fair the full expression is this : {{ files:listing folder="galleries/{{ url:segments segment='2' }}/{{ url:segments segment='3' }}" }} ... I thought about the plugin but all I need is a loop to display images from a particular folder.. I figured the file plugin is more than enough don't you think? Thanks for all your help Phil :) – salmane Oct 08 '12 at 19:00
  • Right, but this is less a case of "just grabbing files from one folder" and more "string concatenation based on URL structure hopefully matching file directory structures", which is getting a little silly. You could make a plugin with a method that grabs the correct folder name from the URL segments available, then just pass that value directly to the attribute. Lex != code :) – Phil Sturgeon Oct 11 '12 at 13:19
  • @Phil: but there are lots of scenarios where you would need to pass the output from a plugin as the input of another plugin... see this for reference: https://forum.pyrocms.com/discussion/24412/calling-plugins-from-within-a-plugin-revisited-but-not. Surely that must be possible...? I tried your suggestion and every other combo available but nothing works. – tobefound Jun 17 '13 at 13:49