I was looking for a way to check the plugin's position within a placeholder in Django-CMS. I found this question Detect last plugin in a placeholder
Is "plugin" a django cms keyword? I can't find documentation about it.
My question is: How can I obtain information about the plugins rendered within a Placeholder?
Thanks
if you don't override your plugins render method (2.4 and up), you'll have your plugin as instance in your context. using the following, you'll get the 1 based position of your plugin:
{{ instance.get_position_in_placeholder }}
also interesting: is_first_in_placeholder and is_last_in_placeholder. in fact, #paulo already showed you the direction in his comment ;) this is the code, with new line number: https://github.com/divio/django-cms/blob/develop/cms/models/pluginmodel.py#L382
Related
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.
I've been playing around with a theme for a ghost blog (ghost.org). It uses handlebars for its templates and I've been looking at existing ones to see what is possible and what isn't.
I have come across {{!< default}}. default is the name of a template.
What does !< mean?
If you look in the index.hbs file of the default theme you'll find this comment:
{{! The comment above "< default" means - insert everything in this file into
the {body} of the default.hbs template, which contains our header/footer. }}
It simply tells the page which parent template it should be inserted into
According to official page section about comments, {{! }} is used to mark a template comment. So, basically < default - just a comment which is simply being ignored.
EDIT:
Also in mustache man page it's clearly stated:
Comments begin with a bang and are ignored.
So, I presume, it's safe to say, that if tag starts with !, it's not going to be rendered.
I want to add a meta keyword tag which have to come with every pages within my drupal website. How to do that ?
It's too easy just use the meta tag module .
And for drupal6 i found this: Meta tags Node Type
Welcome
It might need a bit of tweaking but I built a module that does this.
https://github.com/SpaceBeers/Drupal-7-Meta-Tags-Module
It also lets you set a site wide default title and description which can be overridden for each node. You can select which content types this appears on.
It'd be nice to get some feed back on it.
Just add The code given below at the top of your template.php file (Custom).
drupal_set_html_head('<meta name="keywords" content="CustomKeyword" />');
Done.
I wanted to override page.tpl.php for specific content type.
I have tried these thing, nothing works for me.
page--article.tpl.php
page--node--article.tpl.php
page--node--type--article.tpl.php
page--node-type--article.tpl.php
page--type--article.tpl.php
But when I targetted specific node by number i.e. page--node--8.tpl.php it worked fine.
I think page--article.tpl.php should have worked, but I dont know why its not working.
Please tell me if I am naming it wrong. and how can I debug such things. I have heard I can use Devel module, but know nothing about it. A slight hint in right direction will be appreciated.
Thanks in advance
You have to make sure that your template can handle this ... I got a code snippet that worked for me here:
http://drupal.org/node/1089656#comment-4426790
<?php
function themeName_preprocess_page(&$vars, $hook) {
if (isset($vars['node'])) {
// If the node type is "blog_madness" the template suggestion will be "page--blog-madness.tpl.php".
$vars['theme_hook_suggestions'][] = 'page__'. $vars['node']->type;
}
}
?>
Have you remembered to clear the cache (under Administer > Site configuration > Performance) so that Drupal is 'aware' of your new file & uses this rather than the default.
See here on Clearing cached data
Also, you may need to add a preprocess hook (I haven't used D7 myself, just 5/6 — think this has changed slightly.) This post on Drupal Stack Exchange seems to give more details
I just ran into the same problem.
node--recipe.tpl.php
not
page--recipe.tpl.php
this is, of course, with a content type called 'recipe'.
ALWAYS CLEAR THE CACHE...
Go to /admin/config/development/performance and click the clear cache button. It should be the first thing you do if you've made alterations to the structure of the backend and they're not showing as expected.
Otherwise you almost had it right
page--content-type-name.tpl.php
will allow you to theme the content type template.
I know this is an old question but if others arrive here, the way I override content types in drupal 7 is like this
node--contenttype.tpl
You will need to overwrite the specific node template for the content type if it is anything different than a Basic Page. Please check this out:
http://api.drupal.org/node/19080
Under this page copy/paste the items that are in the node.tpl.php page and overwrite it on how you want. You can access the node specifically by $node
Your template for articles would be:
node--article.tpl.php
Once this is created make sure you clear cache to ensure this works.
So depending on what you are trying to accomplish, there might be some CSS tricks that could help you out.
For instance, to override any CSS rules for a specific node type just remember that your pages for that node type will have a body class of "node-type-[TYPE]" (ie: .node-type-article)
You can then override the CSS as follows:
body.node-type-article #selector {}
Step 1.create a content type for example: my content type is "fullwidthpage"
Step 2. copy page.tpl.php and rename to page--fullwidthpage.tpl in template folder.
Step 3. Add this code to template.php
function <strong>YOUR_THEME_NAME_HERE</strong>_preprocess_page(&$variables) {
if (isset($variables['node']->type)) {
// If the content type's machine name is "my_machine_name" the file
// name will be "page--my-machine-name.tpl.php".
$variables['theme_hook_suggestions'][] = 'page__' . $variables['node']->type;
}
}
Don't forgot to change YOUR_THEME_NAME_HERE
I am using WordPress 3.2.1 ,
Page template selection drop down is missing on Pages (Add,Edit)
wp-admin > Pages >Add New > Page Attributes
I Edit the Template Page Default page as below code
/*
Template Name: New Template
*/
But still the template drop down no visible , my older version of WordPress it display by default.
Following is the screen shot for more idea
I solved this problem solved by adding the typical following code:
/*
Template Name: Custom
*/
Don't add any spaces after Name:
It'll work if you use template name: as well.
It might help someone: check if your index.php file is in place.
If it's not there, wordpress treats the template as corrupt and it doesn't display the template selection.
This should be simple to troubleshoot. The requirements for the page template to work are straight forward:
The template needs the page title in the top of the file like you've shown (the title needs to be wrapped in a PHP tag, you probably just didn't add it with your example bu I want to make sure you havne't overlooked it):
<?php
/*
Template Name: Custom
*/
?>
The second requirement is that the file is in the root of the theme folder.
With those two requirements in place, it should work. If it isn't working you nave a few possible issues. I list a few off the top of my head:
You might need to re-install WordPress in-case a file was corrupted
during your last update.
It's possible someone has altered the WP-Admin layout using users
roles.
That's all I can thing of at the moment, let me know how it turns out.
I had the same issue. It actually turned out to be a missing style.css file within the template directory in my case.
This happens because the get_post_templates() in class-wp-theme.php first checks for errors. If it finds any then it returns an empty array (no templates are displayed).
A side effect of this is that saving a page would clear the existing template and use the page.php instead.
So in short if the errors() method of your theme returns any errors then no templates dropdown.
hope that helps someone.
Same issued, I found out that in appearance panel in your WordPress dashboard the stylesheet is missing. You shouldn't rename the style.css in your theme folder.
Not sure if this will help anyone, but we solved the problem by disabling our theme and re-enabling it again. We had some other theme folders in the theme directory that we weren't using so we deleted those out as well. good luck, it's a really random problem to solve!
yeah!template dropdown not showing because you have no template So how to solve this::---
1 create template folder in theme
2 create a template in this folder
like:-
<?php /* Template Name: Home */ echo "template"; ?>
and check-in page dropdown will be there.