DjangoCMS How do I access attributes of a cms.extensions.TitleExtension in a template - django-cms

Following the official documentation under:
http://django-cms.readthedocs.org/en/latest/how_to/extending_page_title.html I have created a TitleExtension which is up an and running and available in the toolbar of the cms. As example: It is a simple TitleExtension to edit meta tags according to the language of the current page.
My question is now: How do I access the attributes of the inserted values within the template? For a PageExtension several examples can be found but not for the TitleExtension.
If it would be a PageExtension with the name "FooBar" I would access it in the template via "request.current_page.foobar". Is that correct?
How would I do the same for a TitleExtension? Is there a similar comfortable way?

How about something like this:
{{ request.current_page.get_title_obj.foobar }}

Related

How do I set Ghost Blog Custom Routes.yaml Collection Title / Meta Description in my custom template?

Using the Ghost blog routes.yaml file it is possible to use the collections block to create a custom collection made from some tag(s) and / or other data. You can also tell this collection to use a custom theme template see:
https://docs.ghost.org/tutorials/creating-content-collections/
https://docs.ghost.org/concepts/routing/#content-structure
For instance:
collections:
/example/:
permalink: /example/{slug}/
controller: channel
filter: tag:example-tag
template:
- example
All of the above works and my collection properly uses my new example theme file.
The issue is that unlike the tag page (for example-tag) my new custom collection does not have a readily documented way to work with the title etc.
It does not pull the title / meta description from the tag used to build the collection (which would be great for collections built from single tags). In an attempt to work around that I tried some {{#has}} statements but I can't figure out what context the custom route would fit into.
With the above example routes.yaml the title for the custom collection ends up as 'My Site Name (Page 1)' — and there is no Meta Description.
This issue also extends into the Open Graph data which lists an identical title as well as no description for the custom collection.
My guess is that it may be possible to use a data property attached to the routes.yaml file to achieve this (see: https://docs.ghost.org/concepts/routing/#data) but I haven't found a solution as of now.
While my initial attempts at googling for a solution came up empty, this is the best reference I have seen to the issue:
https://forum.ghost.org/t/dynamic-routing-page-post-data-context-in-default-hbs-nested-navigation-on-custom-collections/4204
https://github.com/TryGhost/Ghost/issues/10082
I found a way to work around.
You create a page called example in the Ghost Admin tool.
Customize routes (instead of collections) in the routes.yaml as following:
routes:
/example/:
controller: channel
filter: tag:example-tag
template: example
data: page.example
The page.example will use the metadata of this page in the Ghost.
This is possible only with workaround described in issue: https://github.com/TryGhost/Ghost/issues/10082
Generally do following:
create page Example (with slug example) and fill metadata title & description you want
in routes.yaml alter your collection definition /example/ add following:data: page.example to link your collection root with specified page
now in your template definition example.hbs you could use e.g. {{#page}} {{content}} {{/page}} tag to insert content from your page. You can do it also in default.hbs template which is included from your example.hbs. So replace: <title>{{meta_title}}</title> in default.hbs with following:
{{#unless page}}
<title>{{meta_title}}</title>
{{else}}
{{#page}}
<title>{{meta_title}}</title>
<meta name="description" content="{{meta_description}}"/>
{{/page}}
{{/unless}}
This will set specific title/description for your collection root pages in general way. It is possible to generate schema.org metadata in the similar way. Unfortunately Facebook and Twitter metadata is not so simple to do because, {{ghost_head}} tag in default.hbs already inserts site metadata to this page. Last note: besides {{meta_title}} and {{meta_description}} I suppose you could use all metadata fields defined here.
In default.hbs I added the following block:
{{{ block "metaTitle"}}}
and eg. in post.hbs I filled that block as follows:
{{!< default}}
<div class="content-area">
<main class="site-main">
{{#post}}
{{#contentFor "metaTitle"}}
<title>{{title}}</title>
{{/contentFor}}
...
For other pages like page.hbs, blog.hbs, author.hbs I did the same. I think that solution is more flexible because we have more control over title value.

Internal Tag Parsing in Ghost

Within ghost if I use the following to display all internal tags,
{{#get "tags" limit="all"}}
{{#foreach tags visibility="internal"}}
{{name}}
{{/foreach}}
{{/get}}
How do I display a tag that has a certain string and then string off the beginning.
i.e I want to add an internal tag of:
#META:Cisco / ASA / 8.2.1
But to print Cisco / ASA / 8.2.1 only
Nice question. :)
Unfortunately, I don't think you can do this simply using the built-in features, but you
can create a custom app that registers a custom helper that can do this.
Here's how to do that:
Install the ghost-app package to your Ghost installation
Check out the docs on how to create an app.
Create the app. :)
Modify gscan to recognize your helper.
Since I found your question interesting, I implemented this app myself. You can view and download the source code from here: https://github.com/conwid/RemovesubstringApp
I also wrote a little blog post about how I created it and how you can set it up and modify gscan in detail here: https://dotnetfalcon.com/stackoverflow-adventures-creating-custom-ghost-helpers-using-apps/
With my version, you'll be able to write this in your templates:
{{#get "tags" limit="all"}}
{{#foreach tags visibility="internal"}}
{{removeSubstring name '#META:'}}
{{/foreach}}
{{/get}}
Hope this helps, if you have problems with the implementation or the setup, feel free to ask.

wordpress simple shortcodes not rendered when using Timber plugin

I've recently taken over dev of a Wordpress site using Timber (which I wasn't familiar with). I'm attempting to use a new plugin and accompanying shortcode, which of course doesn't work.
I've been researching this for a couple hours and there doesn't seem to be a simple answer. In order to use a simple shortcode like this:
[sp_faq category="7"]
Do I really need to create a custom shortcode function in functions.php, add some sort of template file for it, etc? This seems counterintuitive to Twig's making things 'simple'.
The documentation for this is less than stellar unless I'm missing something obvious.
You could try this (example using a gravity form shortcode):
{% filter shortcodes %}
[gravityforms id="1"]
{% endfilter %}
If you want to render a shortcode from a custom field you can do it like this:
{{post.custom_shortcode_field|shortcodes}}
Taken from the docs:
https://timber.github.io/docs/guides/filters/#shortcodes
Or if it's comming from the main-editor try:
{{ post.content|wpautop }}
Seems like this is too late for OP, but for anyone else coming across this: The correct solution is combined in the Luckyfella's answer and the comments on it. I think OP would have got it working if he had tried Luckyfella's final suggestion.
You need to put {{post.post_content|wpautop|shortcodes}}* into your Twig file(s). This will render both auto paragraphs and shortcodes that are put into the main WYSIWYG editor, by default.
*post is simply the conventional default name in Timber for a TimberPost, you will also need to check in your PHP template files to see what the Timber context and Timber post variables are called. For OP it seems to have been page, not post.
Just thought I'd chime in here.
post.post_content contains the raw data that is contained in the database (before any filters have been applied to it) and post.content contains the data after the filters have been applied, so using the filter |shortcodes shouldn't be needed to be run on that.
I was using post.post_content for some reason and found this question because I was trying to figure out why my shortcodes weren't working and hence it led me to do some more research.
Now, reading the answers in this question, I wasn't really satisfied with as I had also been using |e('wp_kses_post') to sanatise the data that I output, but if I used something like this:
{{ post.content|wpautop|e('wp_kses_post') }}
...then obviously I would get the correct filtered data with the shortcodes processed, but it would also at the same time strip out any non-allowed data with the e('wp_kses_post') filter.
Sure, you could add allowable tags within this filter, but obviously that isn't very realistic as you don't know exactly what output the shortcodes will be outputting nor do you want to keep updating it.
So, we had a problem... we want to allow shortcodes to be parsed, but also sanatise the content at the same time - what to do!?
The solution is the below:
{{ post.post_content|wpautop|e('wp_kses_post')|apply_filters('the_content') }}
Here we use post.post_content so we have the content before it has been filtered, then after the wpautop filter it is followed by e('wp_kses_post'); this will sanatise the data, but the important part being it will leave shortcodes alone, so they can be still be filtered!
Lastly, we apply the filters for the content with the apply_filters filter, and this then takes care of all the filters applied to the_content including parsing the shortcodes.
Though if you are already using universal escaping you will have to consider how the above will apply to your situation.
Reads like you want to use a shortcode outside of post.content.
You can use {% function('do_shortcode', '[shortcode here]') %} to process a shortcode where ever you want to in a template.

Using Page Name or URL Properties for Handlebar If Statements in Big Commerce templates

I'm currently working on a BigCommerce theme using their Stencil framework. It leverages Handlebars.js for some logic already and I'm trying to use it to show specific html on specific pages.
Looking at the documentation I can see there is a "pages" object and that I should be able to name or URL to do what I need to do.
I cannot figure out the syntax to get the page name or url to run the iff against. I can succesfully get it to do what I want by testing if it's a page content type, but not any of the type properties.
{{#if pages }}
... do foo here
{{/if}}
What I want to do is something like
{{#if pages.url '===' 'about' }}
... do foo here
{{/if}}
{{#if pages.url '===' 'service' }}
... do foo different here
{{/if}}
It looks like you are actually using the wrong Object Model for the data that you are trying to pull. The first word of your handlebars object should be "page" and not "pages". This will pull any content or data from the static pages that you build in the back office. (AKA the WYSIWYG)
Here is a link to the docs of the model that you want. https://stencil.bigcommerce.com/docs/page-content-object
For Example:
{{{page.title}}}
{{{page.content}}}
Note that I am using 3 handlebar on each side to escape the HTML on the WYSIWYG. Let me know if you need any other help.

How do i find the id of a drupal block-id if i know it's block-description

In a specific template i want to use a block, so it's contents can be edited by an editor for all content using that template.
Because the setup is multisite i cannot use the block-id(bid). The id of the block is different for different sites.
Is there a way retrieve a blockid for a block description via the API?
I could use a SQL query on the prefix_boxes table, but would prefer to use a documented API.
I'm currently using the code below on Drupal version 6.
$block = module_invoke('block', 'block', 'view', 7);
print $block['content'];
You can use block_list (Here is the documentation for it: http://api.drupal.org/api/drupal/modules--block--block.module/function/block_list/6) to retrieve the block list per region, there you should find your block id by the description.
But writing your own query isn't bad solution in this case, For my opinion at least.
You do not want to use the block, but a region itself. You can achieve this using the _preprocess_nodehook, adding the region in the .info and printing the region in your template.
By the way, the trick than Ran published is quite interesting as you can use this to write your region in virtually any part of a Drupal site.

Resources