Generate pages from ymal data file

Hi all,

I generated my homepage from the yaml files in the “data” folder, it works well. Now I can generate a new page with other ymal files.
so i create a “services” folder in the “data” folder and put my news ymal files for my new page.
but I feel like it’s not taken into account when I try to access the services page. It expects to have an md file in “content”.
Do you know how to make my ymal files be taken into account for the creation of the new page?

1 Like

unsure what generate means. do you have an _index.md file and use the yaml to populate the page
or are u using a content adapter?

the first option will need a content md file

even empty one is sufficient

---
---

the latter one won’t need one but ofc the adapter.

it always a good idea to follow Requesting Help to get a more appropiate answer.

1 Like

Hi @irkode ,
by generate i mean populate.
yes i was planning to use ymal files to create the pages and i have an _index.md but when i try to access to the new it’s empty.
i have in the “data” folder a folder named “services” for the new page. In this forlder my ymal files. In the “content” folder, i have a service folder and an _index.md inside.

1 Like

the services/_index.md is a list page for the services. from the yaml files in your screenshot i would say you need a services/services.md wher you use the services.yaml. the path would be data/services/services.

just guessing by your description.

for more you will have to share your code

more

1 Like

don’t trust the first description, it was just an example.
in the “services” page, I want to display the different services offered. inside I will have a small description which is in home.yaml and the services:
pentest: pentest.ymal
training: training.yaml
security-asset: security-asset.yaml.
all these files are in /data/services/

for example, security-asset.yaml

enabled: true
id: "security-asset"

content:          
    - image: "images/services-sec-archi.png"
      title: "Security Architecture Assessment"
      text: "A console architecture assessment considers the perimeter and internal network architectures and configurations."
      
                      
    - image: "images/services-custom.png"
      title: "Training and Custom services"
      text: "We are ready to support you in your security needs. Get In Touch "

1 Like

i read that twice and didn’t get what pages you have, what yaml file goes where. and whag exactly does not work.

as told to use data files you will have to have a md file for the page. ech page can use multiple yaml files.

please share your code. if you cannot create a reproducable example illustrating your problen.

read it another time and you can create a page /content/services.md which loads all your yamls.

or /content/services/index.md which will be a leaf bundle where you can add other resources like images to display.

that depends on the stuff around (your other content and templating)

data files reference as

  • site.Data/services/security_assets
  • site.Data/services/pentest

changed the delimiter to _ cause I believe to remember with a hyphen the dot notation won’t work.
you will need to use index function to adress that one something like index site.Data.services "security-assets. not 100% sure .

all code just written and untested. if you cannot get that to work, please provide a repo…saves me from replicating your setup.

yes it’s a repo: GitHub - Sipikat/kulinda-sec at services
what works: home: we see the home page with the different services offered. This part uses the ymal files that are in data/home.
what I want another page with the files that are in data/services. This page will display the different services offered.

quick check. dunno if it’s the only problem

your path to the data files is wrong. you have servic should be services.

cu tomorrow

looks like a lot of tryout history in your project (branch) you provided .

I would recommend to clean up these (expand to check pain points)
  • both a config folder and a config file.
    Use either one of that (looks like your site uses the config file, so remove the config folder)
  • lots of aliases in index.md files.
    i would rather not create these aliases unless you have old links out in the world that you don’t want to break. If you start a new site, there’s no need for that. You should not make the same stuff available using client side redirects on different URLS.
    The blog menu – which has five(!!!) aliases – is commented, seems no neeed to generate that at all (remove or hide that one using draft or build options)
  • typos “service vs services”
    having different stuff in singular and plural is a high risk in breaking things… there’s even a serivesfolder in public ;-). would go with one of that only.
  • the data file for services/training is missing
  • public folder.
    Your build is fast, so I would’t remove the public folder from the repo to avoid side effects.
  • resources folder
    Your build is fast so you could would also remove that. At least clean up from time to time.
  • duplicate templates in theme and local layouts
    don’t touch the themes folder. Add your own stuff to /layouts. For changes copy the source file from the theme to the same path in your layouts and customize there.
  • hint: The theme seems to be about one year old and will break the build with hugo v0.132.0
    haven’t checked if you are on the most recent version.

With the following changes to your site I get a services page that seems to give you what you want:

  • config.yaml and data/home/services.yaml
    change url values inside to use services instead of service → see cleanup section
  • template for your Services section.
    created layouts/services/services.html template (based on your themes\up-business-theme\layouts\services.html). Have a look at Template lookup Order - Section pages for details.
  • fixed the errors in that file
    • changed “servic” to “services”
    • commented line for non existing data file (training)
    • adjusted data path because of the dash inside the name.
    {{ define "main" }}
     {{ with .Site.Data.services.home }}{{ partial "sections/hero.html" . }}{{ end }}
        {{ with .Site.Data.services.pentest }}{{ partial "sections/brands.html" . }}{{ end }}
        {{ with (index .Site.Data.services "security-asset") }}{{ partial "sections/portfolio.html" . }}{{ end }}
        {{/* {{ with .Site.Data.services.training }}{{ partial "sections/services.html" . }}{{ end }} */}}
     {{ end }}
    

thank you very much @irkode . you are awesome !! wondeful.
Problem solved.

quick question: do you know how I can define sections (for example have a pentest, security-asset, training section in the services page) and from the home page make references to these sections?

to change the background color for section in services pages be done in layout and html files?

don’t get it exactly what “defining a section” should be. A section is merely a folder in your content (usually containing an _index.md or index.md) file.

  • for markdown files the standard [name](link) should do (maybe with a link-render-hook) or use ref/relref shortcode
  • for templates there’s a rel/relRef function and absURL or getPage with .Permalink…

please check the docs for these.

This is a different topic. Following One issue, One Topic please open a new topic incl. details (Requesting Help) if you cannot get that working

Ok. thank you very much.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.