Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include div block, only in first particle instance (Twig, Joomla) #3150

Closed
webarion opened this issue May 13, 2023 · 2 comments
Closed

Include div block, only in first particle instance (Twig, Joomla) #3150

webarion opened this issue May 13, 2023 · 2 comments

Comments

@webarion
Copy link

webarion commented May 13, 2023

I create my particle. And there can be several particles on a page.
The particle must have a dynamic modal window. And the modal should be one per page, created by the first particle only. All other particles must work with the modal window created by the first particle.
It's possible to do this through JavaScript, but the question is, is it possible with twig to know the particle's instance number to prevent the modal block from being re-created?

@webarion webarion changed the title Find out if a particle instance has already been loaded Find out if the particle is the second instance. May 13, 2023
@webarion webarion changed the title Find out if the particle is the second instance. Find out if the particle is the second instance (Twig, Joomla)/ May 13, 2023
@webarion webarion changed the title Find out if the particle is the second instance (Twig, Joomla)/ Find out if the particle is the second instance (Twig, Joomla) May 13, 2023
@webarion
Copy link
Author

I found a way to detect that the particle instance is the first one on the page:

{% if gantry.config.index.particles.myParticle|keys|first == id %}
  {{ 'This first my Particle: ' ~ id }}
{% endif %}

Now the question to the connoisseurs is this the right way? And is there a better solution?

@webarion
Copy link
Author

webarion commented May 21, 2023

So, I found a solution that suits me. And this solution is in the documentation:
https://docs.gantry.org/gantry5/advanced/css-js-twig

{% pageblock body_top %}
  <div class="MyModalBlock"></div>
{% endpageblock %}

This way, only one instance is loaded <div class="MyModalBlock"></div>, even if there are multiple instances of the same particle on the page.

@webarion webarion changed the title Find out if the particle is the second instance (Twig, Joomla) Find out if a particle is the first instance (Twig, Joomla) May 21, 2023
@webarion webarion changed the title Find out if a particle is the first instance (Twig, Joomla) Include div block, only in first particle instance (Twig, Joomla) May 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant