Site logo

[Resolved] Insert a Block Template into a Page?

Home Forums Support [Resolved] Insert a Block Template into a Page?

Home Forums Support Insert a Block Template into a Page?

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #2455359
    Tom

    I created a Block Template (Appearance>Elements>Block)
    It calls some dynamic data from Custom Fields associated with a CPT “Positions”
    The Custom Fields are part of a CPT that represents various job positions (welder, fitter, etc).
    I call the block template “Position Template”

    I then want to create a Page that I can assign the block “Position Template” to.
    I then want to associate the page with a specific CPT “Position” (for example “Fitter”)

    On that Fitter Page – I do not know how to:

    1. Call the Block Template I created
    2. Then assign it to the CPT “Position” (Fitter)

    Or am I approaching it incorrectly?
    Thank you!

    #2455429
    Fernando
    Customer Support

    Hi Tom,

    I’m not understanding correctly. Are Positions – Welder, fitter, etc. Posts of your CPT or fields?

    Can you clarify?

    Or, so we can take a closer look at your structure, can you provide admin login credentials?:

    Please use the Private Information field for this: https://docs.generatepress.com/article/using-the-premium-support-forum/#private-information

    #2456128
    Tom

    Fernando…
    1 – Here is a link to an image that TRIES to explain what I am trying to do.
    2 – I am trying to take full-advantage of Custom Post Types and ( I think) Block Templates
    3 – But my approach MIGHT NOT be how Generate Press Works. (I am trying to figure it out – but am not a developer.)
    4 – However – what I am doing, and I think how GP does work, would let me – not only solve my problem of displaying dynamic data on pages – with a single design – but also let me use it a myriad of other places – even landing pages down-the-road.

    Image Link (plus private information below):
    https://imgur.com/cfhBTYV

    #2456291
    David
    Staff
    Customer Support

    Hi there,

    you need to create template files for your CPTs.
    In the GeneratePress Theme folder or from the GitHub

    https://github.com/tomusborne/generatepress

    1. Copy the single.php and the content-single.php to your child theme.
    2. Rename them to match your CPT slug. eg. single-{cpt_slug}.php and content-{cpt_slug}.php
    Swap {cpt_slug} for the slug eg. position or whaterver your CPT slug is.
    3. In your single-{cpt_slug}.php see this line:

    https://github.com/tomusborne/generatepress/blob/e7fbf5693bfe4325a41cae988e3eda16550d4025/single.php#L29

    this code:

    generate_do_template_part( 'single' );

    swap the single for your CPT slug.

    4. Repeat this for each of your CPTS.

    5. Then in your Block Element you can select your Custom post type on the Display Rules.

    #2456315
    Tom

    Gadzooks David! :^) Hopefully I can dive in later this afternoon.

    Question: I do not have a Child theme – that should be the first step correct? Does Generate Press provide one? (I f not – I can make one)…

    Thank you!

    #2456342
    David
    Staff
    Customer Support

    Thats correct and yes we do – read here:

    https://docs.generatepress.com/article/using-child-theme/

    The doc includes a link to a starter child theme zip

    #2457369
    Tom

    Downloaded and installed child theme.
    Followed steps above.

    Still not working – but do not know if I am doing it correctly. Doesn’t seem like it should be that difficult.
    CPT>Elements (Block)>Calling the block from a Page.
    Nothing appears when I preview the Page other than the title.

    Let me know if anything jumps out. Thank you.

    https://imgur.com/a/lhsYJOK

    #2457381
    Tom

    I *think* I figured it out.

    I have the Block>Position Template appearing in the Position> All Positions location.

    IN the Custom Post Type “Fitter”:

    1. I created a Container.
    2. Enabled Dynamic Data
    3. Data Source – Post Type
    4. Post Type – “Positions”
    5. Source Post – “#xxx:Fitter”

    And when I previewed the page it worked.

    The problem I was having (creating for myself) was thinking I had to CREATE a PAGE to display the information from the CPT “Fitter”.

    When in fact it already existed as the Fitter Post itself.

    So – In the Menu – I did not have “Positions” chosen to be visible. Chose Fitter – and it all worked.

    :^)

    #2457781
    David
    Staff
    Customer Support

    The problem I was having (creating for myself) was thinking I had to CREATE a PAGE to display the information from the CPT “Fitter”.

    Yeah i can see how that can be misunderstood 🙂

    Glad to hear you got it working

    #2458065
    Tom

    This is absolutely bad-A**. Love how this is working. I had two years of Drupal experience. Steep learning curve – but once you connected some concepts – it was apparent what you could do with it. GP is as close to that granular Drupal model as you can get within WordPress I would think (and still not be a developer to stretch the capabilities). Websites are a fraction of what I do now, so I have probably forgotten more than I know, but this really helps.

    Thanks for your help & Fernando’s, and Ying’s!

    #2458794
    David
    Staff
    Customer Support

    Super glad to hear that , and we’re happy to be of help 🙂

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.