Create Custom Menu
BeantwortetI've created a custom menu for my help center. I will want it to go on several different templates, such as articles, categories, etc.
Is there a way to create a custom widget or include to reference using handlebars templating? Any help would be appreciated! If there is another more appropriate forum for this question please let me know.
-
Hi Sam,
There is a way to reuse code in several template pages like so:
Say I have an html code I want to reuse:
First, I will minify it and put it in a jQuery html clause:
jQuery('#mycode').html('........');Save this file as mycode.js and upload it as an asset to your template.
Now, in any page you want to reuse this code, add the following lines to your template:
<div id="mycode"></div>
<script src="{{asset 'mycode.js'}}"></script>The first line will add an empty <div> section with an id "mycode".
The second one will get the script we compiled to execute.The script itself is looking for that "mycode" div element and adding the html we wrote in it.
To minify the html, you can simply use online tools like: http://www.willpeavy.com/minifier/
Let me know if you this works out.
--Tal
-
Thanks Tal. I could use some JS, yes. Great suggestion.
I wonder if there is another more vanilla way to create an include and add it to the necessary templates.
Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.
2 Kommentare