Skip Navigation

[Resolved] Content Templates assigned from page editor no longer working

This support ticket is created 7 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 24 replies, has 3 voices.

Last updated by Beda 7 years ago.

Assisted by: Beda.

Author
Posts
#501902

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello Brian,

Thank you for the details. Situation is bit confusing and we apologize for the inconvenience.

This issue I have brought to attention of our Layouts lead developer initially and the last reply I have got after our senior staff and 2nd tier supporter debugged the issue. The problem is also strange as it didn’t happen when I checked it in my WP installation recently.

However, I have discussed a few things with our team and I am going to test a few more things before we can move further. We are trying our best to resolve it and are currently discussing / debugging on this issue, so that we can come to a resolution.

Thank you

#502470

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello Brian,

Just wanted to send you an update, that I have been debugging this issue in your test02 site along with Twenty Sixteen theme. And I have taken some notes on the things that are causing trouble or the behavior is bit strange, but I am not done testing through this complex issue yet. I will be debugging it further and communicate with 2nd tier team to sort things out further.

We will also get in touch with you as soon as we have an update or if we need any further information.

Thank you

#503662

I might also recommend testing those same things using the test01 version of the site, which works perfectly fine and is identical to test02 but doesn't have the latest views/layouts updates applied (the ones that broke it).

#504470

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello Brian,

I have again thoroughly checked the issue on your site and narrowed down the issue using “Twenty Sixteen” theme.

- View display properly >> when inserted into Page, it is displaying the data which is in the Content Templates.

- View is not displaying properly >> when it’s inserted into a Layout using View’s Cell, it is not displaying the data which is present in the Content Templates.

I have escalated this issue to our 2nd tier support for further review and we will get back to you.

Thank you for your co-operation and patience as we strive hard to resolve this.

#504609

Hi Noman,

You got it! This is the exact issue we're having, I'm glad you were able to replicate it.

Looking forward to hearing back from your team, thanks for your ongoing assistance.

Thanks,
Cam and Brian.

#506202

Hi Brian, this is Beda, Toolset 2nd Tier.

1. I do not see any content Template assigned to any page on your Setup for test 02.

2. The Issue you mention is expected.

Let me elaborate.

1. When I create a Content Template (let's forget Layout for a second) then I decide to style content (Post Body) with my Custom Templates.
https://toolset.com/faq/whats-the-difference-between-a-view-and-a-view-template/

There, I can add ShortCodes and HTML to decide how to display things.

Then, I can assign this Content Template to either a SINGLE post or page or to ALL posts or pages of a certain Type.

So far so good, right?
This seems to work just fine?
(again, let's forget Layouts and Views lists altogether for a second)

2. Now, if I create a VIEW, which is a LIST of things, then I can either decide to:
- output the Post Body without any content template
(it will be output just as I add the content to the WordPress Post Body)
- Or, I can use a Content Template (Usually a "View Loop Item")
-- This can be a NEW Content Template (completely different from the above-mentioned one!)
-- OR, it can be the same as is already assigned to Posts or Pages

It is nowhere stated or expected, that if a Post has a Content Template assigned (either single or all of them), that this should automatically be used in a View that lists those posts.

Actually, this is the freedom of design, that we do not force that content template in a View.

ONLY if I specifically call that Content Template when I insert the Post Body ShortCode in a View Loop, it will be applied.

Now, your install uses the wrong ShortCode for Post Body, this has not been inserted with the GUI.

A Post Body ShortCode has always a "view_template" argument, which is either "None" (blank WordPress Post Body is output) OR it has a "name-of-the-content-template" in that argument,
which would then output the post body with exactly that style and contents you added to the Specific Content Template.

But this has not to be automatically the Content Template you assign to posts or pages.

It is the content template you pass in the Post Body ShortCode argument "view_template", or NONE.

3. Now let's look at this with Layouts:

- It is the exact same.
- A view will display either Post Body content without applying a Content Template at all,(view_template=none) OR it will display the Post Body with a Content Template applied (view_template=my-content-template).
It will never automatically call a Content Template, if you pass none.

It never will pull the content Template that is assigned to a Post or all posts by default or single mode, unless I pass that specifically in the Post body shortcode argument view_template, as above shown

This all works as expected, I do not see any issue.

Please let me know if I need to increase my coffee doses on Mondays :), but as far I see, the entire issue here surges from the wrong usage of the ShortCode [wpv-post-body view_template="None"], which you use as [wpv-post-body], and that is not a correct syntax.

I hope, with this your issue is solved, otherwise I am here to help 🙂

#506231

Hi There Beda,

Thanks so much for the response, I'm glad to see you were able to find the issue, however I believe Noman had made significant changes to that demo site.

All the child pages of the homepage did have content templates assigned, I'm unsure if Noman changed that. After updating views & layouts, the content template box in the page editor began to show the "layout is assigned" message instead of the select field, even when no layout was assigned. (See my video on page 1 of this thread, this was another related issue we were having that has not been looked into).

Regarding the usage of the Post Body Shortcode, my concern is that in versions previous to the big views & layouts update, ie. Layouts 1.9.3 and Views 2.3.1, when a content template was *not* defined the Post Body ShortCode, the view *did* in fact show the page's body texts formatted within the Content Templates assigned to those pages instead of 'none'.

You can see that the Post Body Shortcode works as we had expected it to (without defining the template in the shortcode but rather the page itself) on the hidden link version. (This was the exact same site as test02 without the big view/layouts updates - same credentials if you would like to have a look - before Noman attempted to debug it.) Everything only broke after applying those big updates.

Was there something that changed in the handling of this shortcode since Layouts 1.9.3 and Views 2.3.1? Or is this perhaps related rather to the bug with the content template box in the page editor not working?

Feel free apply the updates to the test01 deployment to see what happens on the front end.

Thanks for your attention in this matter,
Cameron and Brian

#506635

Hello Brian,

1. After updating views & layouts, the content template box in the page editor began to show the "layout is assigned" message instead of the select field, even when no layout was assigned. (See my video on page 1 of this thread, this was another related issue we were having that has not been looked into).

This thread has not been handled as it should.
We handle one issue per thread.
https://toolset.com/toolset-support-policy/

This is of course not your responsibility, but I need to stick to one issue here.
If you are OK with it, I would like to stick to the issue with the Content Template not being Displayed in a View Loop of Child Pages or Posts.

For the other issues, I need one ticket each issue. I apologise that this has not been clearly stated at the very begin of this Thread.

2. Regarding the usage of the Post Body Shortcode, my concern is that in versions previous to the big views & layouts update, ie. Layouts 1.9.3 and Views 2.3.1, when a content template was *not* defined the Post Body ShortCode, the view *did* in fact show the page's body texts formatted within the Content Templates assigned to those pages instead of 'none'.

This is definitely not expected.
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-body

The "view_template" parameter is NOT optional. This was never different, and if this used to work the way you describe this, it would have been a BUG.

A View will not pull any Content Template at all if there is none passed in that argument.

I apologise, that in order to solve this issue, all you need to do is pass the proper Content Template in the "view_template" argument.

For the issues you mention with the bad GUI of Layouts and Content Templates (post edit screens, assign either template or layout), I already know what this is, can say that we are on this (there should actually be an Erratum coming soon), but, in order to keep things neat and clean, if you need current assistance with that or more information please open a new Ticket for it.

You may refer to this Thread here, and ask for my assistance.
I usually do not work in the Public Suppport, but I will be happy to assist your Queries since this will (hopefully 🙂 ) improve your impression of Toolset Support and let you go on with your projects in a reasonable time.

Thank you for your patience, I appreciate this, and I apologise that you need to change the ShortCode the way above illustrated to solve the problem.

#506848

Hi Beda,

Re 1: Not a problem, I wasn't sure if they were one in the same issue initially, or related at least, which is why it was mentioned initially in the same thread.
I will keep my eyes out for the Erratum as you have mentioned.

Re 2: I was beginning to wonder if this was in fact a bug that I just happened to be taking advantage of.

Passing the value of the view_template shouldn't be an issue at all: I should be able to simply get the value of the Content Template post-meta field for that post/page (I see the post-meta slug is "_views_template") and pass it into the 'wpv-post-body' shortcode's 'view_template' argument. Notice the similarity between these - _views_template (post meta) and view_template (shortcode attr) - you can understand how I had assumed the output we got was intentional with Views and not a Bug. Regardless, this functionality is easily recreated using a custom shortcode as I'll explain for anyone else following along:

The shortcode [wpv-post-field name='_views_template'] got me the ID defined in the Content Template meta field, however [wpv-post-body] requires the title of the content template, not the ID. Adding [wpv-post-title id="[wpv-post-field name=_views_template]"] does indeed get me the title of the content template assigned to each page/post in the view. Adding that within [wpv-post-body view_template=''] does seem to work, however leaves some leftover closing tags - too many opening and closing shortcodes characters and args inside of eachother of course.

SO I've written a single shortcode that gets the value of the "_views_template" post-meta field, if set, for the current post in the loop. It then gets the title for a post with the same ID and returns it - this successfully gets us the title of the assigned Content Template.

(See code block down below for my [content-template] shortcode script, which can be added to functions.php, anyone feel free to comment if I'm doing something wrong/stupid.)

Adding this new shortcode, [content-template], to the view worked great and showed the Title of the content template that was set for each page in the view.
I also added the shortcode to Toolset Settings > Front-end Content > Third-party shortcode arguments, of course.

However when placed in the 'wpv-post-body' shortcode's "view_template" argument, it still didn't seem to want to work (ie. [wpv-post-body view_template='[content-template]']). I discovered that this was simply due to the names of my Content Templates, which contained what I assumed was a standard dash. The dash character being outputted by my shortcode was in fact the long one, however the 'wpv-post-body' shortcode is expecting the short one, an 'endash'.

I was able to correct the endash issue after discovering there were encoded html characters being used in the titles for Content Templates. Using "html_entity_decode" and a "str_replace('–', '-', ....." resulted finally in the [wpv-post-body view_template='[content-template]'] shortcode combination working great and reproducing the positive results from the "Bug" that we've been exploiting apparently.

Below is the final code for my [content-template] shortcode that resulted from this. When used within [wpv-post-body view_template=''], it will show the page/post body formatted within the content template assigned to that page/post.

/**********************************************************************
*      SHORTCODE TO GET TITLE OF A POST WITH AN ID MATCHING THE SOURCE FIELD
*******************************************************************/

add_shortcode( 'content-template', 'dtf_get_views_template');
function dtf_get_views_template(){
	// Get the ID of the current post in the loop.
	$current_post_id = get_the_ID();

	//Safely get the ID from the Array stored in the _views_template post meta field for the current ID
	if (get_post_meta( $current_post_id, '_views_template', true )){
		$content_template_id = get_post_meta( $current_post_id, '_views_template', true );
	};

	// If returned post meta value was not an empty, let's try to get the title for a matching post by ID, otherwise return nothing.
	if ($content_template_id !== ''){
		$content_template_title = get_the_title($content_template_id);
		$content_template_title = html_entity_decode($content_template_title);
		$content_template_title = str_replace('–', '-', $content_template_title);
		return $content_template_title;
	} else {
		return;
	}
}

You can have a look at either of the /test01/ and /test02/ deployments for this in action, logins are still active for you. To be honest, I'm not sure if I'm handling the character encoding issue properly (didn't try with any other special characters in a content template title), but for our purposes this will work fine and we'll avoid usage of such characters in any future implementations.

With regards to our impressions of Toolset Support, we honestly don't have any current plans of walking away from Toolset - we've now spent quite some time working with it and have created some very elegant solutions that would have been impossible without the use of Types, Views and Layouts - however the lack of acknowledgement and understanding of the problem from the support person who was previously handling our thread was becoming quite concerning. We had never had this much trouble explaining a simple issue in the past with Toolset Support, so after multiple explanations and a full video explaining all the display and editing issues didn't work, we became quite concerned with the dependencies we may have created.

However your answers have pointed out, very simply and elegantly, the issues we were having and why we were having them, as well as the direction we needed to move forward in - we couldn't ask for anything more. Your assistance is greatly appreciated Beda and I'm glad we were able to come to a resolution so quickly after coming into contact with you - thanks again for the timely detailed responses. Your assistance has certainly improved our impressions of Toolset Support and I want to thank you for the detailed and thorough answers related to the hangups we were experiencing as well as your willingness to provide ongoing support on this hurdle. Unless you have any comments, recommendations or suggestions regarding the above script/solution, this thread can likely be put to rest now.

As you have recommended, I will keep an eye open for the Erratum relating to the Content Template post-meta GUI and post a new thread if necessary once applied. Until then I will work on updating our custom toolset themes and any deployments that require the new shortcode in order to prepare them for the Views/Layouts updates.

Again, feel free to have a look at test01 or test02 (I corrected the changed layouts and templates to ensure the solution worked in the updated version as well) to see how the Single Page Layout and "Child Pages" View works to dynamically display pages with different Content Templates for each if you have any interest.

Thanks again for your ongoing support,
Cameron

#507175

Great, the code looks good, you got a good hand to comment what you write, this is valuable for the future. Too many coders omit the comments part 🙂

Your code works, of course, it's a cool solution for this specific purpose actually.
The thing about the argument "view_template" is simply that it is a mandatory argument.
So usually you will add an already existing template name there, but your solution is elegant if you use several posts templates, and want them pulled automatically also in a Views Loop.

Related to the Views/Layouts GUI, it is now more focused on Layouts.
The current error is that if you assign a Content Template instead of a Layout manually, The GUI tells you, there is no Layout because it uses a Content Template and no Content Template because there is a Layout-
This is wrong, and it'll be fixed soon.
It's not that it doesn't work, it's just extremely annoying and confusing since you need to do everything through Toolset > Content Templates > Change Usage, instead of how it was previously, through Post > Edit > Content Template.
As said this will be fixed, I will update you here when it is.

Related to support, I am glad you kept your trust into the Plugin and our Services.
We will always try to give our best, sometimes this can fail, and there is no excuse for this, unless that all humans can fail.
As long we learn and grow from that, I think we all will be fine 🙂

Looking forward to see you in the Forums again, and I thank you for the patience and the shared code above, this also contributes to Toolset!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.