Page 1 of 1

CGBlog images not showing in detail template on default page

Posted: Tue Jun 12, 2018 10:48 am
by howey
Hi

A conundrum? I have CGBlog installed and have a page that has a main tag in the content block

Code: Select all

{CGBlog detailtemplate="00_newsdetail" detailpage="latest-news" number="1" category="General" action="detail"}
Which should show the latest post.

I then have a tag in a content block forming the right hand column which gives a list of posts.

Code: Select all

{CGBlog summarytemplate="00_newspagesummary" detailpage="latest-news" number="5" category="General" detailtemplate="00_newsdetail"}
Both use the same detail template. However when you navigate to the page the post in the main content shows up with the text, but the images don't show. If I then click on the link in the right hand column the images do show?

I am using the following code to select the appropriate image.

Code: Select all

{if isset($entry->fields)}
  {foreach $entry->fields as $field}
    {if $field->type == 'image' && $field->name == 'Standard Image' && $field->value != ''}
{capture name=newsdetailimg assign=standardnews}{CGSmartImage src1=$entry->file_location src2=$field->value  max_width="1000" max_height="800" class="img-responsive" noembed=1 alt=$entry->title}{/capture}
    {/if}
  {/foreach}
{/if}

{if isset($entry->fields)}
  {foreach $entry->fields as $field}
    {if $field->type == 'image' && $field->name == 'Revolving image' && $field->value != ''}
{capture name=newsdetailimg2 assign=revolvingnews}{CGSmartImage src1=$entry->file_location src2=$field->value  max_width="1000" max_height="800" class="img-responsive" noembed=1 alt=$entry->title}{/capture}
    {/if}
  {/foreach}
{/if}

{if $standardnews != ''}
    {$standardnews}
    {elseif $revolvingnews != ''}
    {else}---
{/if}
I think it is probably something to do with the way the page is processed. I seem to think that this might be a resent change. Although I can't remember the administrator says the images used to show?

I have tried just calling the image directly without the capture, but the result is the same.

I am running 2.2.7 with all the latest associated modules. PHP version 5.5.38. The only resent changes are upgrade to 2.2.7 and installation of CG content utilities.

Any help would be gratefully received.

Re: CGBlog images not showing in detail template on default

Posted: Tue Jun 12, 2018 2:46 pm
by DIGI3
If the output of the captured variables isn't in the same template, you need to give them a global scope.

So after the captures, you could add:

Code: Select all

{$standardnews=$standardnews scope=global}
{$revolvingnews=$revolvingnews scope=global}
Note: I think there are better and more efficient ways to do what you're doing, but that should at least determine if it's a scope issue.

Re: CGBlog images not showing in detail template on default

Posted: Tue Jun 12, 2018 2:48 pm
by velden
My first step would be to just print the contents of the fields to the page. To check if that works.

Put this code somewhere in the top of the detail template you use and then check on the frontend if it has the values as you expect.

Code: Select all

<pre>{$entry->fields|print_r}</pre>

Further, it's not very efficient to iterate to 'all' fields twice only to find one value, which you already know where to search for it.
You already know the name, you know the field is of type image, so you only want to check if it's not empty

Code: Select all

{if $entry->fields['<FIELD_NAME>']->value != ''}
...
{/if}
(note: I don't know if CGBlog uses field ALIASES in stead of NAMES. You can check this in the output of the earlier mentioned {$entry->fields|print_r})

Then, {capture} is said to be expensive. So you might consider to use assign.

Re: CGBlog images not showing in detail template on default

Posted: Tue Jun 12, 2018 6:50 pm
by Rolf
Smarty scope code examples at http://cms.ms/Hupy

Re: CGBlog images not showing in detail template on default

Posted: Tue Jun 19, 2018 2:17 pm
by howey
Hi

I am still struggling with this.

I have tried the various suggestions:

Code: Select all

{$standardnews=$standardnews scope=global}
{$revolvingnews=$revolvingnews scope=global}
Which didn't make any difference.

I added the

Code: Select all

<pre>{$entry->fields|print_r}</pre>
Which didn't print a list of fields in the news page (I'm using CGBlog instead of the News module as it has more flexibility in the categories etc.) when you navigated straight to that page, it just displayed the number 1. But when you click on a "news" story in the right column it then displayed the full set of fields?

As the CGBlog tag is added in the default content block on the page

Code: Select all

{CGBlog detailtemplate="00_newsdetail" detailpage="latest-news" number="1" category="General" action="detail"}
I'm assuming it's not processing all the fields. But I am not sure how to make these "variables" available when just navigating to the page, rather than click on a CGBlog story to get the detail.

Re: CGBlog images not showing in detail template on default

Posted: Tue Jun 19, 2018 4:22 pm
by velden
I would suggest to hire someone to check it out for you. Can't imagine it takes longer than half an hour to find the culprit and come up with a working solution.

If that's not an option post the full page template and full detail template. Further post the name of the content blocks and their contents.

An url to the resulting page would help too probably.

Re: CGBlog images not showing in detail template on default

Posted: Tue Jun 19, 2018 6:18 pm
by Rolf
Did you follow/read this blog too? http://cms.ms/JntZ
Note the way the content blocks are installed!

Re: CGBlog images not showing in detail template on default

Posted: Tue Jun 19, 2018 8:08 pm
by Rolf
Ohw, this blog is also describing a similar situation http://cms.ms/yovH

Re: CGBlog images not showing in detail template on default

Posted: Thu Jun 21, 2018 9:36 am
by howey
Hi

Thanks Rolf, from first read that appears to be where the solution lies.

I'm always interested to learn new things where I think I should be able to understand the problem or it fits within my scope of experience. If we stop learning we might as well give up. It's great to get support from the forum.

However, there are times when I have paid for additions and help Velden. I have supported these enhancements so that they can be included in the CMS core. I think we can all benefit from a thriving community.

Know for more head scratching!

Re: CGBlog images not showing in detail template on default

Posted: Thu Jun 21, 2018 10:51 am
by velden
However, there are times when I have paid for additions and help Velden. I have supported these enhancements so that they can be included in the CMS core. I think we can all benefit from a thriving community.
Sure, no problem of course. I didn't know whether you were facing a deadline or something.

Posting the templates could really help as the order of things may be important in this case.