Hello, I just had a conversation with some coworkers. Some are thinking that all the pages must be coded in the index.md of content/concernedpage/ . This method presents an obvious advantage to allow the next coders to use a bunch of shortcodes they created to code a webpage really fast (you put a list of shorcodes with changing parameters) then it is displayed by a generic single.html
looking like this : {{ define "main" }}{{.Content}}{{ end }}
. My opinion would be to code everything in the layouts (except the blog post for exemple) to benefit the logic of Hugo like the {{range}} or {{if}}
.But the counterbalance is that you cannot use shortcodes in the layouts or you have to do some tricky moves with .Scratch ect … and it 's a pretty great loss of time. For you, which one is better practice ?
No, but you can use partials
with almost the same code/logic
And you can do that:
shortcode service.html
{{ partial "service.html" . }}
Thanks for your quick reply. But is it possible to pass information to partial without using .Scrath ? Because the benefit of shortcodes is to send a bunch of information like this {{< a-title-4-card-hover-links icon_1="fas fa-sign-in-alt" title="sometitle" >}}
and reuse them directly in the shortcode to make it generic.
Have a look at the dcumentation.
You can pass a dict
to the partial. So PLENTY of parameters
Example I use everywhere for assets/images
{{ partial "image_asset.html" (dict "context" . "path" .image "size" "x150" "action" "Resize" "title" .title) }}
I do not understand what it means and what they are trying to achieve.
I suspect that this team comes from an other language/logic. If you try to think in the way hugo works, all will be smooth, instead of trying to force hugo to works the way they think.
Let s image the site’s root is http://mysite.com. They think that the http://mysite.com/schedules page should be coded in /content/schedules/index.md using a lot of shorcodes(like a centered section with image at the top and text under). My opinion would be to code in the /layout/schedules/list.html. But thanks you answered my question
Yes.
IMO i prefer to structure my site in the layouts. Much more powerfull. You can even get further with page type/layouts defined in your frontmatter case by case
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.