How to add fields to standard Page blueprint

admin

#1

Hello,
I’m new to this.
I’d like to be able to input certain information when making a new post:

  • Category
  • Tags
  • Author
  • Source Name
  • Source URL

(I’m making a news site which is mostly links to other sites)

I’m using the Admin plugin and the Project Space theme (because I like the layout)

in user/config/site.yaml I found a list of taxonomies and I added a few to it:

taxonomies:
  - category
  - tag
  - author
  - srcname
  - srcurl

sometimes these extra taxonomies appear in the admin plugin as textfields that I can input information but not always. I’m not familiar enough with the backend to understand why this is happening.

Have I done the correct thing - to add these taxonomy options? or is there a better / proper way of doing it? Might the Project Space theme (I installed the Project Space skeleton) have something to do with this?

Thanks so much for your help, bye
Adam


#2

@adamburton Looking at the names of the newly added taxonomies I wonder what the intention is behind these new taxonomies. The names suggest you would like to add new fields to the header instead of ‘categorising’ blog items.

Taxonomy (general), the practice and science (study) of classification of things or concepts, including the principles that underlie such classification.


#3

@pamtbaau - yes, you’re correct. Is there a more appropriate way to do this that also allows me to input this information as part of the page creation process in the admin plugin? rather than using taxonomies

thanks, bye
Adam


#4

@adamburton You could try the following:

  • First, you need to create you own inherited theme, else any changes you make will be overridden when the base theme gets updated. Creating an inherited theme can be done in two ways, manually and by using the ‘devtools’ plugin.

    • Creating inherited theme manually
      Follow the first 5 steps in https://learn.getgrav.org/themes/customization#theme-inheritance to create the required files.
      NB. Everywhere you read ‘antimatter’, replace it by ‘quark’
    • Using devtools plugin
      The ‘devtools’ plugin will create all required files/folders automatically.
      • In the terminal, change the directory to the root of the Grav installation
      • Install and run the devtools. It will ask some questions you need to answer.
        $ bin/gpm install devtools
                (on Windows: $ php bin/gpm install devtools)
        $ bin/plugin devtools new-theme 
                (on Windows: $ php bin/plugin devtools new-theme)
          Enter Theme Name: MyTheme
          Enter Theme Description: My New Theme
          Enter Developer Name: Acme Corp
          Enter Developer Email: contact@acme.co
          Please choose an option
             [pure-blank ] Basic Theme using Pure.css
             [inheritance] Inherit from another theme
             [copy       ] Copy another theme
            > inheritance                           <- Type in 'inheritance'
           Please choose a theme to extend:
             [0] quark
            > 0                                     <- Type in '0'
        
         SUCCESS theme mytheme -> Created Successfully
        
         Path: /path/to/grav/user/themes/mytheme
        
  • You have now the basic infrastructure of a new theme inheriting from ‘Quark’

  • Tell Grav to use the new theme. Open file ‘/user/config/system.yaml’ and set the correct value for the theme:

    pages:
      theme: mytheme
    
  • We can now finally create a new template/blueprint to use in Grav’s admin and add our own properties.
    Create the file ‘/user/themes/mytheme/blueprints/default.yaml’ to extend the ‘default’ blueprint used by the Admin panel for creating pages. See docs on page blueprints for more information.

  • Add the following form definition:

    extends@: default
    
    form:
      fields:
        tabs:
          type: tabs
          active: 1
          fields:
            options:
              type: tab
              title: PLUGIN_ADMIN.OPTIONS
              fields:
                myfields:
                  type: section
                  title: My Fields
                  underline: true
                  fields:
                    header.author:
                      type: text
                      label: Author
                      placeholder: Enter authors name
    

In Admin a new section ‘My Fields’ will be added to tab ‘Options’. When saving the page, you will get a page with a header similar to:

---
title: My page title
author: 'John Doe'
taxonomy:
    category:
        - art
    tag:
        - modern
---

In Twig you can access the author value using {{ page.header.author }}

Hope this helps.

Cheers.


#5

@pamtbaau - that’s really helpful, thank you so much, I really appreciate your clarity.

I’ll try this after work and let you know how it goes.

bye
Adam


#6

@pamtbaau - hello
I’ve been trying to get my head around this but not got very far because I really am no good with the terminal. I’ve just spent two and a half hours trying to install grav on my computer and I find it so tiring and difficult that I’m going to give up.

I really appreciate your help.

Is there a way to make an inherited theme without using the command line?

thanks, bye
Adam


#7

@pamtbaau - hello, I found this:

https://getgrav.org/blog/theme-development-with-inheritance

which I wish I’d found three hours ago. Anyway, I’m going to bed now so I’ll have a look at it some other time.

bye
Adam


#8

actually, in the comments of the above linked blog post people seem to be saying that it doesn’t work and that the correct procedure is here:

https://learn.getgrav.org/themes/customization#theme-inheritance


#9

@adamburton I’m sorry my response wasn’t clear enough. After re-reading the docs I pointed at, I can imagine it might have caused some confusion… I have updated my answer and tried to add some more clarity and guidance.

The blog you are referring to is 4 years old and was written in the very early stages of Grav. Things have changed a bit…

If you don’t mind sharing where you got stuck in the creation of the new theme, I might being able to help you get across that block.


#10

@pamtbaau - hello
don’t worry, it’s not that you’re response wasn’t clear, it’s that I find it very difficult to use the command line, I find it very confusing and I’ve got very little experience, so I try to avoid it. I tried to do it last night but it just kept stalling me, trying to install composer didn’t work, php didn’t work, njinx didn’t work so I’ve given up.

I’ve been following the instructions here: https://learn.getgrav.org/themes/customization#theme-inheritance but that’s currently stalled because, at Step 5. where I’m trying to “create a new theme Class file” there’s a line in the mytheme.php file:

class Mytheme extends Antimatter

which I want to change to

class Mytheme extends Project Space

because I’m trying to build on, inherit, the Project Space theme, but it won’t let me use Project Space, or project-space or projectspace - I don’t know why, so I can’t get past this point.

Thanks for updating your answer. Unfortunately, for me, I’m going to avoid the command line because it just takes too long, it never goes my way - and that’s not only based on this experience, I’ve been trying to get into using the command line for years and it always goes wrong, everyone says it so easy but there’s something that prevents it from working for me.

If you have any suggestions for the mytheme.php problem I’m having I’d appreciate it.

thanks, all the best

Adam


#11

@pamtbaau

just to say, I found that using ProjectSpace worked in the mytheme.php file

the next problem is when I load the site it says:

"Template "default.html.twig" is not defined."

and loads of other error stuff that I don’t understand. I’m not sure what happening there. I feel like I followed the instructions on that page quite carefully, but maybe not, I’ll have a look through them again.

bye
Adam


#12
class Mytheme extends Project Space

In PHP a class name cannot contain spaces…

Have a look at ‘/user/themes/project-space/project-space.php’ and you will see the class is named ‘ProjectSpace’. You might try the following:

class Mytheme extends ProjectSpace

#13

@pamtbaau hey, sorry, I we must have been typing at the same time. Thanks for that, I managed to find that project-space.php file and saw ProjectSpace.

I’ve now got this issue with the

"Template "default.html.twig" is not defined."

and I’m not sure where that comes from. hmmm


#14

How does your ‘/user/themes/mytheme/mytheme.yaml’ look like? That should also not contain spaces when referencing Project Space.

streams:
 schemes:
   theme:
     type: ReadOnlyStream
     prefixes:
       '':
         - user/themes/mytheme
         - user/themes/project-space

If the definition is not ok, you will receive the error ‘Default template “default.html.twig” not defined’.

The name ‘Project Space’ seems to be an evil omen for errors caused by spaces…


#15

predictably, I’d typed something in wrong.
So, it seems like it is working now.

Thanks again @pamtbaau for your perseverance.
The form definition you suggested above has worked also. That’s great.
When I want to add another field, how should I do this?

bye
Adam


#16

Give a man a fish, and you feed him for a day. Teach a man to fish, and you feed him for a lifetime.
–Maimonides

Have a look at A First Example from Example: Page Blueprints.


#17

Thanks so much for your help @pamtbaau

I’ve got my head around this part of it now, and I’ve managed to get grav running on my my machine which is making things slightly easier.

all the best, bye
Adam