Snippets

Can we use Snippets in Snippets

11 months 4 weeks ago #88623

Octav A's Avatar Octav A

Hello,
Please advise if we can we use snippets in snippets like this

snippet1 id = {snippet country-GB}
snippet1 contet = United Kingdom

snippet2 id = {snippet dynamic-country}
snippet2 content = php that returns dynamically country codes

and use like this {snippet country-{snippet dynamic-country}}

Thanks

11 months 4 weeks ago #88630

Peter van Westen's Avatar Peter van Westen Admin

No, you can't nest Snippet tags like that.
But why not flip the logic?
Just use:

{snippet country}
And in that, use php to dynamically output one of the specific country snippet tags, like:
{source}<?php 
$country = ....
echo '{snippet country-' . $country . '}';
?>{/source}
Or use ReReplacer Pro to handle that initial tag.
You don't even have to call it {snippet country}, just use whatever you want, like:
[country]
And then use ReReplacer to replace that with that piece of php code which outputs the Snippet tags:
<?php 
$country = ....
echo '{snippet country-' . $country . '}';
?>

11 months 3 weeks ago #88634

Octav A's Avatar Octav A

Thanks for prompt reply. Rereplacer would be already to much regularlabs plugins for our website:)
this one

{source}<?php $country = ....echo '{snippet country-' . $country . '}';?>{/source}
does not work but i found a solution to only php within a snippet.
Thanks, and keep on doing your wonderful job.

11 months 3 weeks ago #88642

Peter van Westen's Avatar Peter van Westen Admin

👍

11 months 3 weeks ago #88715

Jonathan's Avatar Jonathan

I think this is a really bad idea. What is the reason that the snippet is not designed to be nested? This is actually a GREAT way of building assets block by block and keeps consistency and re-usability. All you have to do is make it recursive.

What this would let me do is:
1) define the parts of my contact information
{{PHOTO}}
{{ADDRESS}}
{{PHONE}}
{{EMAIL}}
{{FACEBOOK}

2) create a signature so that SIGNATURE =
<p>{{PHOTO}}</p>
<p>{{ADDRESS}}</p>
<p>{{PHONE}} | {{EMAIL}} | {{FACEBOOK}</p>

11 months 3 weeks ago #88717

Peter van Westen's Avatar Peter van Westen Admin

You can use other snippets inside the content of a snippet.
So nesting in that way is possible.
But you cannot place snippet tags inside a snippet tag.
So this is not possible:

{snippet first-{snippet second}}

11 months 3 weeks ago #88720

Jonathan's Avatar Jonathan

I understand what you're saying, I have used other systems where they let you nest and it's very helpful because it makes things extremely consistent, and also allows us to gradually build more complex blocks of information. I am suggesting that you figure out a way to make it nestable because it's extremely useful that way

11 months 3 weeks ago #88725

Peter van Westen's Avatar Peter van Westen Admin

What are you trying to do?
Why isn't using the {snippet} tags inside the Snippet content enough?

11 months 2 weeks ago #88821

Octav A's Avatar Octav A

Peter van Westen wrote:

What are you trying to do?
Why isn't using the {snippet} tags inside the Snippet content enough?
I confirm it is enough like this or using some php code:)

11 months 2 weeks ago #88832

Jonathan's Avatar Jonathan

I think we just mixed up what we're saying.

We can put a snippet reference inside another snippet reference.


We cannot put a snippet tag within a snippet tag like this {{snippet {{snippet some-stuff}}}}

11 months 2 weeks ago #88834

Peter van Westen's Avatar Peter van Westen Admin

Yes, exactly like I explained 🙂