Question

How can I insert fixed HTML into Gantry 5 particles?

Answer and Explanation

Inserting fixed HTML into Gantry 5 particles can be achieved through several methods, each with its own advantages. Here's a breakdown of common approaches:

1. Using the "Custom HTML" Particle:

- Gantry 5 provides a "Custom HTML" particle specifically designed for inserting HTML code. This is the most straightforward method for adding fixed HTML.

- Steps:

- In the Gantry 5 Layout Manager, drag and drop the "Custom HTML" particle into the desired position.

- Open the particle's settings.

- Paste your HTML code into the provided text area.

- Save the particle settings.

- Pros: Simple, direct, and no need for additional files.

- Cons: Can become cluttered if you have a lot of HTML, and it's not easily reusable across multiple particles.

2. Creating a Custom Particle:

- For more complex or reusable HTML, creating a custom particle is a better approach. This involves creating a new particle file with your HTML.

- Steps:

- Create a new folder in your theme's particles directory (e.g., my_custom_particle).

- Inside this folder, create a file named my_custom_particle.yaml (or similar) with the particle's configuration.

- Create a file named my_custom_particle.html.twig (or similar) with your HTML code.

- In the .yaml file, define the particle's name, description, and any settings.

- In the .html.twig file, write your HTML code. You can also use Twig templating for dynamic content.

- In the Gantry 5 Layout Manager, your new particle will be available to drag and drop.

- Pros: Reusable, organized, and allows for dynamic content using Twig.

- Cons: Requires more setup and knowledge of Gantry's particle system.

3. Using a Custom Twig Template:

- You can also create a custom Twig template and include it in a particle. This is useful if you want to keep your HTML separate from the particle's main file.

- Steps:

- Create a new Twig template file in your theme's templates directory (e.g., my_custom_template.html.twig).

- Write your HTML code in this file.

- In a particle (e.g., a "Custom HTML" particle or a custom particle), use the Twig include function to include your template file.

- Example: {% include 'my_custom_template.html.twig' %}

- Pros: Keeps HTML separate, reusable, and allows for dynamic content.

- Cons: Requires knowledge of Twig templating.

4. Using a Text Editor with HTML Snippets:

- While not directly related to Gantry, using a text editor with HTML snippet functionality can speed up the process of inserting HTML into the "Custom HTML" particle.

- Steps:

- Configure your text editor to store HTML snippets.

- When you need to insert HTML into a "Custom HTML" particle, use the snippet feature to quickly paste the code.

- Pros: Speeds up the process of inserting HTML.

- Cons: Doesn't directly address the reusability or organization of HTML.

By using these methods, you can effectively insert fixed HTML into Gantry 5 particles, choosing the approach that best suits your needs and complexity of your HTML content.