[Resolved] snippets of reusable code

This thread is resolved. Here is a description of the problem and solution.

Problem:
The user would like to create some HTML and reuse it across the site.

Solution:
You can use a shortcode on the legacy views or a view block with Gutenberg. The shortcode is "wpv-post-body"

[wpv-post-body view_template="my-content-template-slug"]

You may also consider to use a third-party plugin such as:

Relevant Documentation:
https://toolset.com/documentation/user-guides/views/views-shortcodes/#vf-153372

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 6 replies, has 2 voices.

Last updated by Franco Calcagni 1 month, 2 weeks ago.

Assigned support staff: Jamal.

Author
Posts
#1580891

We need to create some code snippets (i.e. the DIV of the main menu) to be used within custom templates so to have only one ource to be changed if the code within the snippet shall be modified.
For example if we add a class to the DIV, we need that class shall be applied wherever that snippet is recalled (even in multiple custom templates).
Is there something available to get that result?
I specify that we are using the traditional editor for the content templates since eww know that Toolset does not yet support the custom JS box in the block editor.

Thanks for any help on this.

Franco

#1580993

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

Hello Franco and thank you for contacting the Toolset support.

I am not really sure to understand your use case. Do you want to have a reusable Javascript snippet then include it in some posts/pages or in the whole site?
Can you elaborate more on what you would like to have?

#1580997

Hi Jamal,
what I need to have is the possibility to insert some snippets of HTML code, for example the DIV of the main menu:

<div class="menu">

  • Item1
  • Item2
  • Item3

</div>

In this case we need something like a shortcode or other element that refers to the source of that code, so if we need to change the class"menu" into "main-menu" we do not have to re-edit every single content template.

Is it something available in Toolset?

Franco

#1581015

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

Of course, that is possible.
You can create an unassigned content template, insert your HTML/CSS/JS.
Then you can use that content template inside any Toolset View or Content Template.

You may also consider to use a third-party plugin such as:
- https://wordpress.org/plugins/shortcoder/
- https://wordpress.org/plugins/post-snippets/

I hope this helps. Let me know if you have any questions.

#1581023

Great news, how is possible to insert an unassigned content template within another cotent template?

#1581041

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

You can use a shortcode on the legacy views or a view block with Gutenberg.

The shortcode is "wpv-post-body"

[wpv-post-body view_template="my-content-template-slug"]

Check its documentation here https://toolset.com/documentation/user-guides/views/views-shortcodes/#vf-153372

#1583683

My issue is resolved now. Thank you!