Orchard Core CMS - Is it possible to get an existing content item, to be shown in another content item? - orchardcms

I've been struggling to show an existing content item to a another content item, what I can do as of now is just add the content part in a content item with using Flow and Bag, but the user really has to fill up the fields for these stuff. What I am trying to do here is for example make a styled 'button' (with the tags and such) with prefilled text in the button, then the user can edit it anytime within the content item it is called.
I am using orchard core with .net core 5.0

There are multiple ways to do this, the way I like to do it for styling is to make a content part with different fields, usually text fields and once the field is created, edit the field and change the editor type to predefined list, once this predefined list is created, one of them can be selected as default. Then add this content part as a part on the parent content type image of fields on contentpart image of predefined list
Another way would be to create a content picker field on an item, that's how you can include other content types on a parent item, I find this approach good for bigger content items (I.e. contentbanners etc) content banner content picker image
This approach is good but you have to use the contentitem filter (Liquid or razor) to get the content item as the parent content item only includes a reference to the content item and not the actual item.
{% for ContentItemId in Model.ContentItem.Content.ContentSections.Banners.ContentItemIds %}
{% assign contentSection = ContentItemId | content_item_id | shape_build_display: "Detail" %}
{{ contentSection | shape_render }}
{% endfor %}
The Third way, if you want content creators to add buttons etc in html editors etc would be via using shortcodes. shortcodes

Related

Which twig template to extend for a custom theme?

I apologise before for a long explanation - I have a hard time explaining it to myself.
I run Shopware 6 locally and using the development template. I needed to remove the product number from the product detail page. So, I override the twig template "buy-widget.html.twig":
{% sw_extends '#Storefront/storefront/page/product-detail/buy-widget.html.twig' %}
{% block page_product_detail_ordernumber_container %}
{% endblock %}
Works as expected - if I have not change the layout template for the product, but using the Shopware default.
But, when I change the layout to a custom layout (the only difference is that the image thumbs is bellow the main image) the product number is back?!
Checking with the Symfony Profiler, I can see that it's now another twig template (from a folder "component/.." responsible for displaying the product number.
Question: Am I correct to assume that I should extend the twig template from this component folder if I'm using a custom layout? I have not find anything in the docs about these "small" details. And if one need to be sure that a custom theme works in every case, you must make the changes (using sw_extends) in two files?
/ Magnus

How to define a specific page template that will be used when displaying node--content-type--full.html.twig

I'm new to Drupal and having a difficult time figuring out the file structure that I need to render my content correctly.
Here's what I have:
A content type called resource_library - with several resource items uploaded
A view called resource-library, which displays all resource library items.
A page template called page--resource_library.html.twig that currently has scaffolding (sidebar etc), then reffers to {{ page.content }} - which renders and loops the resource items from this file - node--resource_library.html.twig
Another file called node--resource_library--full.html.twig which displays full contents of the resource items.
The problem is that when I go to my /node/6 to view a single resource item I can see that it loads from page.html.twig, which does not have the same scaffolding similar to page--resource_library.html.twig.
My question is, is it possible to define the page template that will be used to display a single node? And if not, how do I achieve this? How do I make this specific content type node full views to look different/unique from any other nodes for content types?
Or am I going about this the wrong way? I'm working with Drupal9.

Sending entry data to embedded template

I have a basic ecommerce site which has a products page, in which a full overview of the products is displayed, including thumbnails, brief description, etc. On the same page, and other pages on the site, there is a sidebar which lists the products by title only.
Since the sidebar is reused around the site I want to set this as an embedded template.
With this setup, must I retrieve all the products from the database twice; once in the main Products page, and again in the sidebar? Or is there any way to speed things up on the Products page by retrieving the entries once in the parent template and passing them to the embedded page?
For example:
products parent template:
<html>
{exp:channel:entries channel='products'}
// display full product info
{/exp:channel:entries}
{embed='includes/_products_sidbar' data={entries}} // ^ Can I pass all the data from the above loop to this embedded template?
</html>
embed:
{if data}
// if we already have the data available then use it without having to get it all again from the database
{else:if}
// if not then use another entries loop:
{exp:channel:entries channel='products'}
// display a list of products
{/exp:channel:entries}
{/if}
I think you are better of using a different approach. Have a look at layouts:
https://docs.expressionengine.com/latest/templates/layouts.html
or, if that's not possible, you can use stash https://github.com/croxton/Stash too.
oh yeah, you'll get better help on https://expressionengine.stackexchange.com/

Bolt CMS - fetch content from contenttypes.yml

I'm currently on this feature, but a solution is far for me. I've tried many things, but i'm turning around my self.
Example: In the Content type "Entries" are more entries. I added a field with "type=select" and "values: entries/title".
How can i fetch the content from these "values" in the twig file?
Has anyone Ideas or Tipps?
you can use the following for the select field:
values: entries/id,title
So it saves the ID of the selected entry. Then in your template do the following to get the record:
{% setcontent selected_entry = 'entries/' ~ record.your_select_field %}

Global Content Block in Grav CMS

I'm using the Grav CMS and would like to have a block of global content present on each page. In other words, every page on the site will have this same block of content (near the footer). I'd like the content of this block to be editable similar to other pages, through a .md file. Instead of hardcoding the content of this block into the base.html.twig (or another) template the content should be editable through a .md file similar to other pages.
One option, use find() to pull the content of the page I want into each page. The downside to this is that I don't want this page to appear in the navigation. If there is a way to hide a page from the navigation this might work however.
What is the recommended way to accomplish this?
I solved this by creating a variable containing the page object from the page I wanted. Within the base.html.twig template I did the following:
{% set secondpage = page.find('/_page_url') %}
{{secondpage.content}
The _page_url is hidden due to the _, but still editable as a normal page.

Resources