I have configured SeoBundle as stated in docs:
sonata_seo:
page:
title: Default title
metas:
name:
description: Defualt description
keywords: key1, key2
cmf_seo:
title: seo.title
description: seo.description
content_listener:
enabled: false
And placed in base.html.twig:
<head>
{# meta #}
<meta name=viewport content="width=device-width, initial-scale=1">
<meta name="format-detection" content="telephone=no"/>
{{ sonata_seo_title() }}
{{ sonata_seo_metadatas() }}
...
</head>
Now when I refresh page I can see that sonata_seo block title and description are set instead of cmf_seo. In docs there is a warning:
The title and description template is only used when the title is not
set on the content object or when the content object is not available,
otherwise it'll use the default set by the SonataSeoBundle. You should
make sure that the defaults also follow the template.
If only docs would clarify what is "content object" would be great... Anyway I tried removing title and description from sonata_seo block:
sonata_seo:
page: ~
cmf_seo:
title: seo.title
description: seo.description
content_listener:
enabled: false
Now my title becomes "Sonata Project" which is default SonataSeoBundle title.
How do I display cmf_seo title? {{ cmf_seo_title() }} is not working.
what is the value of seo.title and seo.description is it something you expect to be translated? Can you serve a longer stacktrace for the exception please?
In general CmfSeoBundle expects some placeholders (%%content_description%%, %%content_title%%, doubled to make it translatable at the end) to enrich the title/description with dynamic data. That dynamic data can live as SeoContent on the document (content object) you are persisting or as so called extractors which fetch the data from the document (content object). In the first case you have to implement SeoAwareInterface in second case you can find several extractors in the [doucmentation[(https://symfony.com/doc/current/cmf/bundles/seo/extractors.html).
If you wanna simply set static titles, you should stay with the SonataSeoBundle. We do simply enrich a template defined in cmf_seo.title|description with dynamic data from the current content. We do need sonata_seo.title for pages with no content documents (i.e. static pages).
Related
What I hope to do is to change the content of description pages of site dynamically in database, for now the description page is loaded from yml file using sonata.seo.page like this :
//sonata_seo.yml
page:
default: sonata.seo.page.default
separator: ' | '
title: Name_site
metas:
name:
keywords: some keyword....
description: "this description stored in dataabse??"
I called it like this {{ sonata_seo_metadatas() }}
So I can change it anytime in admin dashboard of site, any idea?
When I have an error in my custom WordPress theme I would like to output the webmaster email address which would be webmaster#mydomainname.com but I am a bit baffled on how to do this in Twig/Timber in the most straightforward way: <p class="text-danger fw-bold">PAGE ERROR - Please contact Webmaster at webmaster#{{ #notsure# }}</p>
webmaster#{{ site.url }} just outputs: webmaster#https://mywordpress.local which obviously won't work.
UPDATED: To get by I am using webmaster#{{ site.url[8 :] }} as that strips away the https:// and outputs webmaster#mywordpress.local but seems there should be a cleaner way somehow?
There are two ways to do this:
You can use Advanced custom field. Make a email field and then print that value inside the twig file. Inside advanced custom field, you can add any email you have no need to extract a domain name. For more information follow this reference: https://timber.github.io/docs/guides/acf-cookbook/
Second method is the way you doing is correct but you need to split domain name from site.url using slice method:
{% set website = "https://mywordpress.local" %} //
//calcualting length of string
{% set lengthOfWebsite = website|length %}
//using length here to split the string accordingly. 8is for split "https://" from actual domain name.
{% set domainName = website|slice(8,lengthOfWebsite) %}
webmaster#{{domainName}}
For the first line of code in your case will be:
{% set website = site.url %}
For the last line
webmaster#{{domainName}}
can also be replaced by:
{% set actualDomainName = 'webmaster#' ~ domainName %}
{{actualDomainName}}
I have a layout included in another one that display my menu. The labels of my menu items need to be dynamic (like the unread messages number of a mailbox). Then I did this :
My orders
(
{{ render(controller('MyController', {'etat':2})) }}
<span style="color:red">with {{ render(controller('MyController', {'etat':2})) }} in late</span>
)
I would like to display labels according to the number that return my controller. I don't know how to get it in a variable.
When rendering your template in your controller
return $this->render('twig_template_name.html.twig', array('variable_name' => $variable);
you pass a variable to the twig template in the array of options as I showed. Your code
{{ path('mypath',{'etat': '2' }) }}
prints a path defined in the routing.yml under the 'mypath' section and ends up adding a GET request variable to the link ('?etat=2'), if 'mypath' showed an absolute route 'www.website.com/yourpath',
{{ path('mypath',{'etat': '2' }) }} would produce 'www.website.com/yourpath?etat=2', which would send your controller for a route /yourpath/{etat} a variable etat with a value of 2 so all you need to do now is change 2 with an actual dynamic value which you receive from another controller.
I am not sure what etat is but lets say it's an article and it has it's id, you have a blog page with lots of articles and the controller that prints them all out sends an array of articles to the twig template, on your twig template you do something like:
{% foreach article in articles %}
{{ article.title }}
{{ article.story }}
read more
{% endforeach %}
And you end up something like:
Catchy Title
Awesome story about code without bugs and where deadlines depend on how creative and well designed and implemented the solutions are
[read more]
and you ofcourse click on "read more" and end up on the url ~/article/2 because the article had an id of 2, your controller for that url receives a variable id in the request, you do a $id = $_GET['id']; and grab the article from the repository and send it to the template.
Hopefully this answered your question, I am very tiered so forgive me if i was confusing which I surely was.
Given a custom Jekyll collection in a folder _stuff, where each document has some metadata, how do I render that metadata using a layout template to an output document? I suspect I need a plugin to do any more than iterating over a collection. E.g. in _config.yml:
collections:
stuff:
output: true
permalink: /stuff/:path
In collection item, e.g. _stuff/thing1.md:
---
title: Thing 1
some_data: 123
layout: stuff-detail
---
Using layout, stuff-detail.liquid:
---
....
---
<div>Stuff Item Data: {{ page.some_data }} (doesn't work)</div>
In your stuff-detail.liquid file you'll need double brackets around your liquid call: {{ page.some_data }}
Try to use this code on your layout stuff-detail.liquid:
<div>Stuff Item Data: {{ page.output }}</div>
See how it works as explained here.
If I have a YAML list, e.g:
Home : /
Terms and Conditions : /terms.html
And I want to render some content from that list, but make use of both keys & values, I'm having to use {{eachProperty}} to get those values, i.e :
{{#eachProperty this.value}}
{{key}}
{{/eachProperty}}
Anyone got any better ideas?
I think you just need to add another layer to your YAML data structure, so you have a list of pages, where each page is an object that has both a title and url property you can reference in the template. In the example below, I put the YAML at the top of the Handlebars template, but it should work the same if loaded from an external file.
---
links:
Home:
url: '/'
title: 'Home'
Terms:
url: '/terms.html'
title: 'Terms and Conditions'
---
<!DOCTYPE html>
<html>
<body>
<h1>Test List of Links</h1>
<ul>
{{#each links}}
<li>{{title}}</li>
{{/each}}
</ul>
</body>
</html>