Using perch:content in multiple places
Hey,
So for instance I have <perch:content id="facebooklink" /> in my footer, which is fine and works, but I also want the same information inside a different HTML template?
When I copy the code to another template it just spits out blank?
Thanks
Kieran
You would need to show us your template.
I cant untill tonight, so for now ill elaborate encase you can see what I mean.
I have a html template called 'social_media_icons.html' in the template folder, this template is then being called in the footer, so the icons end up in the footer. Which is fine, perfect.
I have another template called seo.html where I want to display some of the same information that is in the 'social_media_icons.html' template into the 'seo' template. So I don't have to write out the same information twice in the admin.
The <perch:content id="facebooklink" /> is in the 'social_media_icons.html' template, and I want the same info it spits out, in the 'seo.html' template, but it just comes up blank.
Hopefully this is a little better to understand? I will still post the templates later on if needs be.
Thank you
Post your template when you are able, otherwise I'm just guessing.
Just passed by; Kieran, you may be looking for template includes https://docs.grabaperch.com/docs/templates/includes/
Thanks for replying, it's not the whole template I want to include, its just a few of the <perch:content /> tags.
You can include template partials. Remember that tags are namespaced - you can't use a
perch:content
tag in a non-Content app context. For example, if you're talking about the exampleseo.html
template for page attributes, that needsperch:pages
tags.With template includes you can use
perch:content
tags and then userescope="parent"
to bring them into scope.Also, apart from the namespacing issue, you can make a template called facebooklink.html and include that in the social media template as well as in another place. So just "modularize" more.
Template partials? importing a partial section from a template?
Is that what I need to do or do I just need to add the re-scope and it will work?
I cant be making template.html files for every line of information id have hundreds.
The facebook link is already being outputted at the bottom of the page so I should be able to output the same information somewhere else just using code.
Is your goal content reuse or template reuse?
my goal is to reuse content that is inside a template.
it's just a <perch:content /> tag that I want to use in different templates.
Ok. Content isn't inside a template. You use a template to display content from a region or a page or an app. You can use multiple different templates to display the same content. You can also pass content into templates from multiple sources.
If you had a region like this in your footer, containing links to your social media profiles:
that would obviously be using a default template. If you wanted to show maybe just the Facebook link somewhere else, you'd create a new template with just that part in it, and then do this:
Sorry for the confusion from my part :-) Cheers
Yeah that's what i'm doing as of the top part of your response.
As for the bottom part, you are saying just create another template even if it's just for one line of information? (in this case a facebook url).
How would I then display it in a line of code such as:
inside 'seo.html' template?
The thing is I already have this link set in another template, I then need it to show in another template (as the above post) aswell.
You can pass it into your page attribute template. See here:
https://docs.grabaperch.com/docs/templates/passing-variables-into-templates/
Ok so that's confused me a little.
Where would i put the code for this so that I could use it accross all templates?
and where would the input fields in the admin turn up?
Ill try this out and if to no avail will post my exact codes up. Cheers
Ok, what I need is the google content from 'social_media.html'
/templates/content/social_media.html
</li>
To appear inside the google link in 'facebook.html'
templates/pages/attributes/facebook.html
Your templates don't store content. Which region uses
social_media.html
?My footer.php which is stored in the global folder.