Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Support

How to edit partials from admin panel as page?

Started by 01K 7 years ago · 11 replies · 963 views
7 years ago

Hi there!
Just started working with Grav.
I've static html+JS template page which I'm trying to start using with Grav.
There are many HTML raw code which I've placed in the page. Making things simpler to manage I put that static html code into partials.

But this code should be manageable - it should be editable.

So, for instance, I've partial called footer-form-block.html.twig

In page content it's called by {% include 'partials/footer-form-block.html.twig' %} expression.
How I could edit footer-form-block.html.twig through admin panel?

7 years ago

Hi @01K, my approach to something quite similar (if I understand your post correctly) to this has been to create a Grav page to hold content I want editable in the admin, and then render the content from this page within my Twig template. Perhaps in your case you would need to render that page content using that particular Partial (via the include statement)?

For example, here is how I handle an editable Footer in my Open Course Hub skeleton:

https://github.com/hibbitts-design/grav-theme-bootstrap4-open-matter/blob/master/templates/partials/base.html.twig#L18

https://github.com/hibbitts-design/grav-theme-bootstrap4-open-matter/blob/master/templates/partials/base.html.twig#L104-L106

https://github.com/hibbitts-design/grav-skeleton-course-hub/blob/master/pages/footer/default.md

I hope the above might be helpful to you.
Paul

👍 1
7 years ago

Hi!
Thank you! I will try this today

👍 1
7 years ago

I've now one issue: all my inserted html code is treated as text and placed into < pre > and < code > tags now.
I've turned off twig and markdown options in admin panel for that page, but no luck.
Also, I've put the markdown="1" tag into the root element with markdown on - but also - no success. Any tips?

The block outputs data like this:
{% set videos_block = page.find('/videos-block').content %}
{% if videos_block %}
{{ videos_block }}
{% endif %}

without raw filter

Thanks

last edited 05/27/19 by 01K
7 years ago

Hi @01K, I am not sure why that is happening... where is that 'block' you are mentioning and how is it being called? I don't think you would need to adjust twig and Markdown options from their default.

7 years ago

Hi, @paulhibbitts
I've main page called Home. Between html code I wrote this call:

TWIG
{% set videos_block = page.find('/videos-block').content %} 
{% if videos_block %} 
   {{ videos_block }} 
{% endif %}

Then I've created the page videos-block and pasted plain html code in it.
Once the Home page is rendered it outputs mine "old" code with edits and once it comes to the {{ videos_block }} part it outputs all inserted code in < pre > and < code > tags. Very strange behavior...
P.S. I have edited my previous post, of an error in tags display

7 years ago

Maybe try the find without the .content item? Also, sounds like you did already but have you tried videos_block|raw? Sorry, I am not too knowledgable in this particular area...

7 years ago

@paulhibbitts:
videos_block|raw ?

yes, I've tried this - no luck 😕

7 years ago

ah, it was all in cache...

👍 1
7 years ago

OH! I should have suggested that along the way too! Glad you got it going🙂

👍 1
7 years ago

BTW @01K, what was the final Twig you used?

7 years ago

In a home page, as it was, with raw filter ->
{% set video_b = page.find('/videos_block').content %}
{% if video_b %}
{{ video_b|raw }}
{% endif %}
And in video_block page I've turned on the Twig checkbox in admin's panel

👍 1

Suggested topics

Topic Participants Replies Views Activity
Support · by Thomas, 1 week ago
2 56 13 hours ago
Support · by Anna, 3 days ago
2 61 16 hours ago
Support · by Justin Young, 17 hours ago
1 32 17 hours ago
Support · by Duc , 1 week ago
2 66 5 days ago
Support · by Colin Hume, 1 week ago
2 59 5 days ago