Help with using capture in News Module

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
becfret
New Member
New Member
Posts: 8
Joined: Tue Mar 18, 2014 1:34 pm

Help with using capture in News Module

Post by becfret »

Hi,

I've managed to use capture to get Open Graphs and Twitter Cards to work with the News Module for title, description etc... but I can not get it to work for images. I'm using the following in the News Template:

Code: Select all

{capture name="facebookphoto" assign="fbphoto"}{$entry->file_location}/{$field->value}{/capture}
but all it captures is:

/uploads/news/id28/

Any suggestions?

Thanks,

Becky
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3484
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: Help with using capture in News Module

Post by velden »

Better post the whole News detail template here.
becfret
New Member
New Member
Posts: 8
Joined: Tue Mar 18, 2014 1:34 pm

Re: Help with using capture in News Module

Post by becfret »

Hi,

Here's all of the template:

Code: Select all

{* set a canonical variable that can be used in the head section if process_whole_template is false in the config.php *}

{capture name="facebooktext" assign="fbtitle"}{$entry->title}{/capture}
{capture name="facebooknewstext" assign="fbdescription"}{eval var=$entry->summary}{/capture}
{capture name="facebookphoto" assign="fbphoto"}{$entry->file_location}/{$field->value}{/capture}

{if isset($entry->canonical)}
  {assign var='canonical' value=$entry->canonical}
{/if}

{if isset($entry->fields)}
  {foreach from=$entry->fields item='field'}
     <div class="newsPhoto">
        {if $field->type == 'file'}
	  {* this template assumes that every file uploaded is an image of some sort, because News doesn't distinguish *}
          <img src='{$entry->file_location}/{$field->value}' alt='' />
        {else}
          {$field->name}: {eval var=$field->value}
        {/if}
     </div>
  {/foreach}
{/if}
<h2>{$entry->title|cms_escape:htmlall}</h2>
<p class='postedby'>
{if $entry->author}
    <span class='author'><strong>{$author_label}</strong> {$entry->authorname}</span>
{/if}
{if $entry->postdate}
    <span class='day'> {$entry->postdate|cms_date_format}</span>
{/if}
</p>
<p>
    {eval var=$entry->content}
{if $entry->extra}
		{$extra_label} {$entry->extra}
{/if}
</p>
{if $return_url != ""}
<div id="NewsPostDetailReturnLink">{$return_url}</div>
{/if}
Becky
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3484
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: Help with using capture in News Module

Post by velden »

You're using the $field variable while it's not yet there.

Code: Select all

{foreach from=$entry->fields item='field'}...{/foreach}
As you can see the foreach loop 'creates' the $field variable.
You could move your code to just before or after this line:

Code: Select all

<img src='{$entry->file_location}/{$field->value}' alt='' />
Example:

Code: Select all

...
<img src='{$entry->file_location}/{$field->value}' alt='' />
{capture name="facebookphoto" assign="fbphoto"}{$entry->file_location}/{$field->value}{/capture}
...
becfret
New Member
New Member
Posts: 8
Joined: Tue Mar 18, 2014 1:34 pm

[SOLVED] Re: Help with using capture in News Module

Post by becfret »

You are a superstar! Thank you so much, works perfectly :)
Post Reply

Return to “Modules/Add-Ons”