Page 1 of 1

[solved]Customize and Separate Custom Fields in CGBlog

Posted: Wed May 05, 2010 9:45 am
by kalozura
Hello all

I have created several custom fields in CGblog  and I'm looking to style  and display each of the differently and I was wondering if there  was  a way to separate them in the summary or details template. I want to be able to call out each of them separately. Is that possible?

right now i have default code:

Code: Select all

{if isset($entry->fields)}
  {foreach from=$entry->fields item='field'}
     <div class="CGBlogSummaryField">
        {if $field->type == 'file'}
          <img src="{$entry->file_location}/{$field->value}"/>
        {else}
          {$field->name}: {eval var=$field->value}
        {/if}
     </div>
  {/foreach}
{/if}
which calls them all together and in a certain order.

Again, is there a way to pull each custom field separately? Thanks!

Re: Customize and Separate Custom Fields in CGBlog

Posted: Wed May 05, 2010 10:27 am
by janb
Hi

Just comment out the foreach section like below and access each field like this:

Code: Select all


{if isset($entry->fields)}
{*
  {foreach from=$entry->fields item='field'}
     <div class="CGBlogSummaryField">
        {if $field->type == 'file'}
          <img src="{$entry->file_location}/{$field->value}"/>
        {else}
          {$field->name}: {eval var=$field->value}
        {/if}
     </div>
  {/foreach}
*}

{$entry->fields.0->name} {$entry->fields.0->value}
{$entry->fields.1->name} {$entry->fields.1->value}
{/if}

If you want to know which fields is available, add this to the end of the template:

Code: Select all

{$entry->fields|@print_r}

JanB

Re: Customize and Separate Custom Fields in CGBlog

Posted: Wed May 05, 2010 2:51 pm
by kalozura
Thanks JanB

This was exactly what I wanted. :)

Re: [solved]Customize and Separate Custom Fields in CGBlog

Posted: Fri May 07, 2010 12:48 am
by Larry
I was looking for the same solution for News... Thanks alot. Saved my day :) Good for me they are based on the same setup.

Re: [solved]Customize and Separate Custom Fields in CGBlog

Posted: Fri May 07, 2010 12:52 am
by calguy1000
These problems are simple
all you have to do is your required reading
like the SMARTY MANUAL.

Too many people ask questions and bump threads and wait days when all they have to do is follow the instructions in the README, do a few google searches, and spend an hours worth of reading.