0
Welcome Guest! Login
0 items Join Now

Gantry 5 Custom Particle Question

  • Gantry 5 Custom Particle Question

    Posted 9 years 3 months ago
    • I have successfully created a new particle with its corresponding twig, yaml, and php files. All is good and my test code is working. The primary purpose of this particle will be to view or increment a count maintained in a database, via a call to a php function. A module (Gantry 5 Particle) will be used to contain and place the new particle in a layout position. So far, so good.

      However, I would like to use multiple instanses of the module to increment different database records. I would like this to key off of an id attribute in an HTML tag which is a parent of the particle. I could do this by creating multiple particles with each one operating on a different counter; I would prefer to use a single generic particle for all counters. QUESTION: Is there any way for code in a twig file, or a php function called via the twig file to determine id's or classes in a containing HTML tag?
    • Matt's Avatar
    • Matt
    • Preeminent Rocketeer
    • Posts: 22270
    • Thanks: 3224
    • messin' with stuff

    Re: Gantry 5 Custom Particle Question

    Posted 9 years 3 months ago
    • Just stick and ID field in your YAML file that places an id=# in your HTML element... is that what you're after?
    • SEARCH the forum first! These boards are rich in knowledge and vast in topics. This includes searching just the 'Solved' forums, using Google, and using ChatGPT :woohoo:
  • Re: Gantry 5 Custom Particle Question

    Posted 9 years 3 months ago
    • Thanks Matt. I'm always amazed how you respond to questions so quickly. Unfortunately, I think your suggestion doesn't quite resolve my issue. What I'm seeking is a generic (custom) particle including yaml, twig, and php files which is defined only once as a particle, but used multiple times in page layout or different module instances. For each instance that the particle is used, I would like to obtain the class or ID of the HTML tag used to contain the particle. The class or id of the containing HTML which is not part of the particle will uniquely define each instance. I guess what I am saying is that I would like the twig to inspect the containing or "parent" HTML code. I would like any id or class to be accessible to the twig so that it can be passed as an argument in a PHP call defined in the twig. If this is not possible, I could use your suggestion to define multiple particles, each with their own unique id in the yaml, however this is not my preferred approach. The PHP functions used in the particles would be the same, except for the id. The id will be used as a "key" or reference to a specific record in a database which is used as a counter. This counter will be displayed on the page or incremented in the database depending on which PHP function is used.
  • Re: Gantry 5 Custom Particle Question

    Posted 9 years 3 months ago
    • Upon further reflection, maybe the twig can't access the HTML code, because it is being used on the server side to create it's HTML and call its associated PHP functions. What I would really like to do is use Javascript on client side which is invoked by some event, to call the PHP code defined in the particle and would be executed on the server side. I don't know if this is possible or if it is, how to make such a call. Possibly using jQuery.ajax. If this is possible, a link to some sample code would be quite helpful.
    • Matt's Avatar
    • Matt
    • Preeminent Rocketeer
    • Posts: 22270
    • Thanks: 3224
    • messin' with stuff

    Re: Gantry 5 Custom Particle Question

    Posted 9 years 3 months ago
    • Would an ID at the Block Level Wrapper work?

      <div class="g-block">

      You can simply add unique ID's via the Layout Manager to any Particle, at the Block level, via the Block tab

      docs.gantry.org/gantry5/configure/layout-manager#settings-2

      :)
    • SEARCH the forum first! These boards are rich in knowledge and vast in topics. This includes searching just the 'Solved' forums, using Google, and using ChatGPT :woohoo:

Time to create page: 0.077 seconds