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.
Related
I'm using the events calendar plugin for Wordpress with a Timber based theme. I'm currently using a previously documented method to integrate which is here:
https://theeventscalendar.com/support/forums/topic/events-pages-not-showing-up-in-timber-based-theme/
Since v5 of the plugin there is an option [set to default too] which uses the updated calendar and event designs that breaks my current integration method. I've tried to update my template PHP files but with little success.
The legacy functions which are relatively simple to call using the function() method in Timber are:
<?php tribe_events_before_html(); ?>
<?php tribe_get_view(); ?>
<?php tribe_events_after_html(); ?>
https://timber.github.io/docs/guides/functions/
However in the v2 templates added to The Events Calendar in v5 they are calling a class, e.g:
use Tribe\Events\Views\V2\Template_Bootstrap;
get_header();
echo tribe( Template_Bootstrap::class )->get_view_html();
get_footer();
The main problem I have is that I'm unsure how to expose this class to the Timber context. If anyone could give me a steer it would be much appreciated. What I have now works fine but the tribe_get_view function is deprecated and considered legacy so is not going to be around for ever so I need to come up with some sort of solution.
Thanks!
Right so the method I posted is no longer require at all and neither is a work around. Just make sure you have a page-plugin.twig template available. Hopefully this will help anyone else who ends up in a bit of a rabbit hole.....
To clarify, there is a workaround in timber/starter-theme, which involves multiple files, including a 'page-plugin.twig' template. Don't just add a 'page-plugin.twig' template and expect that to fix it.
Third party plugins that hijack the theme will call wp_head() to get
the header template. We use this to start our output buffer and render
into the view/page-plugin.twig template in footer.php
Go here https://github.com/timber/starter-theme.
Copy the header.php, footer.php, and page-plugin.twig into your theme and customize for your own site.
The method documented here: https://mcintosh.io/using-the-events-calendar-plugin-with-timber-and-twig/
Worked for me. You create a default template file and a matching twig template:
[your theme]/tribe/events/v2/default-template.php
[your theme]/[your twig template directory]/events.twig
The default-template.php file contains this line:
$context['tribe_markup'] = tribe( Template_Bootstrap::class )->get_view_html();
Which can be rendered like this in the events.twig template:
<div class="events-container">
{{tribe_markup}}
</div>
Note that you will need to have to select "Enable updated designs for all calendar views" in events > settings > display
I think the div.events-container may be needed for the default stylesheets, but haven't tested otherwise.
I am trying to get all pages from ghost blog.
{{#get "posts" limit="all" filter="page:true"}}
Doesn't work.
If you are running on latest Ghost instance (or at least the version that has Content API ^2.10.0).
You can use limit=all attribute to fetch all page resouces like so:
{{#get "pages" limit="all"}}...{{/get}}
You can find more about the limit attribute in Ghost Docs for {{get}} helper and page resource here
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.
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 }}
I made a navigational bar at the left side of my blog and I wanted to add the list of pages that the user created into that navigational element. The problem is that I do not know how to loop through static pages. When looping through normal posts all users approach this method:
{{#foreach posts}}
....
....
....
{{/foreach}}
The above code is to loop through each post that exists and then the user has the choice to put whatever they want inside that piece of code. The problem is now looping through each static page.
Can anyone show me how to loop through static pages?
At this time, it is currently not possible to loop through static pages :(
That will prob come out when Apps do (aka someone will make an app for it)
I was searching for just this today and found a solution on this Github issue
{{#get "posts" filter="featured:true+page:true"}}
{{#foreach posts}}
... do something with all featured pages...
{{/foreach}}
{{/get}}
I just verified this locally.