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

Best practices

Started by Muut Archive 11 years ago · 17 replies · 503 views
11 years ago

Hello,

maybe this topic can be for Grav-learners like me.

Since two days ago I play with Grav and it is exciting!
I have done the "Theme Tutorial" and have a (for now default) page with 3 elements which I put in a Bootstrap-grid with inline HTML.
Could you please tell me if this is the best practice?

Thank you, Olli

11 years ago

There are no hard-and-fast rules in Grav about how you must do things, you really need to experiment with it based on how you want things to look, and how you prefer to manage your content.

I prefer to keep layout-things in the theme's twig templates as much as possible. If there's more complex layouts required you should look at modular-pages as a possible solution by breaking up a single page into multiple modular elements.

You can also make use of the page-inject plugin to inject other pages into a page, this way you can reuse common page elements in other pages.

My least favorite option is putting HTML into the markdown files themselves. This makes things harder to maintain over time, and just seems hackish :)

11 years ago

Thank you for your answer!

I will do it with a template.
Would you take a standard or modular page for the following layout?

Text
Text text text
Text

11 years ago

i'm partial to modular pages for multiple blocks of 'stuff'. Check out the One Page Skeleton for an example of this.

11 years ago

It was fun to get the layout how I want it to be!

Layout

If you don not mind I have some questions.

My .md and .twig for the 3 columns are as follows:

.md
.twig

Can I somehow loop through Markdown-headings and Markdown-texts so I don not need to write the 3 columns in the header?

Olli

11 years ago

You could put some kind of divider in the content, then split the content into an array based on that divider, then loop over those items in the array. I've done something similar in the lightslider plugin.

11 years ago

This sounds very good!

So I just need "---" above the second and third heading in the .md and a .twig (I have seen "split" and "hr" in your .twig)?

11 years ago

Sadly I can not get the loop to work.
Only if you have time, could you please show me how the .twig should look like?

My original .twig:

{{ content }}
<div class="row">
{% for feature in page.header.features %}
<div class="col-md-4">
{% if feature.header %}
<h2>{{ feature.header }}</h2>
{% endif %}
{% if feature.text %}
<p>{{ feature.text }}</p>
{% endif %}
</div>
{% endfor %}
</div>

Thank you, Olli

11 years ago

obviously i'm testing with some simple table html for clarity, you would need to adjust the html to whatever you needed.

11 years ago

Thank you!

Can I safely delete the whole width-constraining?

/ Constrain the width /
.container {
width: auto;
max-width: 960px;
padding: 0 15px;
}

11 years ago

Well, delete it and see if it has the effect you desire. I mean, not sure what theme that's from, and what you are trying to do, but it will undoubtedly 'break' the width restriction.

11 years ago

Sorry, from your theme tutorial. I was not sure if this was done for a reason.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1332 9 years ago
Archive · by Muut Archive, 9 years ago
2 923 9 years ago
Archive · by Muut Archive, 9 years ago
2 4053 9 years ago
Archive · by Muut Archive, 9 years ago
1 2931 9 years ago
Archive · by Muut Archive, 9 years ago
3 1109 9 years ago