Search
Other Snippets questions
Forum

My snippets are rendered twice in the layout, and I have trouble with dynamic variables

Rikard J's Avatar Rikard J
Hi
I have a problem with my snippets. They are rendered twice and default variables aren't passed. This goes for all of my snippets.

For example, I have made this snippet called "Button"
<a href="%url%" class="uk-button %class%"><span uk-icon="%icon%"> </span>%text%</a>

Is has four variables, three with default values (placed after | in the below list)
url | #
class | uk-button-primary
icon |
text | ...

For some reason the default values aren't passed to the rendered version. So in the front end this HTML is rendered:
<p><!-- START: Snippets -->
<a href="/" class="uk-button "><span uk-icon="" class="uk-icon"> </span></a>
<!-- END: Snippets --></p>

But that is not all, the snippet gets rendered twice, and along with it, all other content in that article. Adding more snippets to the same page does not make extra copies of the article. It happens only once regardsless of how many snippets I add to the page (I have only tested up to 5 snippets)

If I pass text to the variables these are used in the rendered view, but the problem with the duplicate content remains.

I have tried to make different snippets, but I get the same result with each one. Even snippets without variables.


I'm using:
Joomla 4.1.3
Snippets 8.3.1 [pro]
php 7.4.29

Any ideas on what I might be doing wrong?

Best regards,
Peter van Westen's Avatar Peter van Westen ADMIN
Please use the correct syntax. See:
docs4.regularlabs.com/snippets/going-fur...ing-dynamic-snippets
Please post a rating at the Joomla! Extensions Directory
Rikard J's Avatar Rikard J
Hi Peter, I really thought that I had gotten the syntax correct. I can't see what I am doing wrong comparing my snippet to the examples. To to be extra sure, I made an exact copy from the example page, copy/paste. I still get the duplicate.

On my article:
{snippet alias="copyright" year="2019" company="My Company"}

In the snippet:
%year% - %company% - All rights reserved

and the variables are defined as:
year
company

The rendered page's HTML looks like:
<div class="uk-width-2-3@m uk-first-column">           
<h1> test </h1>
<div class="uk-panel uk-text-meta uk-margin">Monday, May 16</div>
<div class="uk-panel uk-text-lead uk-margin">
<p><!-- START: Snippets -->2019 - My Company - All rights reserved<!-- END: Snippets --></p>
</div><div class="uk-panel uk-margin">
<p><!-- START: Snippets -->2019 - My Company - All rights reserved<!-- END: Snippets --></p>
</div></div>

Best regards
Peter van Westen's Avatar Peter van Westen ADMIN
Ok, I thought you were using bars ('|') to separate the variables.

Not sure why it is outputting twice.

Can you give me (super) admin and (s)ftp access so I can take a look?
And tell me on what url I can see/reproduce the issue.
You can use the 'Confidential information' button in the forum editor to hide sensitive information.
Please post a rating at the Joomla! Extensions Directory
Rikard J's Avatar Rikard J
Thank you Peter.
Sorry I wasn't clear that the bars were just a graphical element here to separate the variable from the default value. Please find the requested information below.

Confidential information:
(hidden)


Best regards,
Peter van Westen's Avatar Peter van Westen ADMIN
This seems to be down to your template.
It doesn't matter what content you place in the article, it is displayed twice.
Try replacing it with 'abc'.
Please post a rating at the Joomla! Extensions Directory
Rikard J's Avatar Rikard J
Oh my, that's so embarrasing, I am so very sorry that I bothered you. The problem was indeed the template and it was an easy fix. The duplication is now gone. I also see that I need to completely remove variables from the tag to use the default value, which means that
{snippet alias="button" url="" class="" icon="" text=""}
is different from
{snippet alias="button" }
Now that I understand that, everything is working like a charm.

Thank you very much for your help and sorry again that I bothered you.

Confidential information:
(hidden)
You can only post on the extension support forum if you have an active subscription and you log in

Buy a Pro subscription