Welcome, Guest. Please login or register.
Did you miss your activation email?
13 May 2008, 04:02

Login with username, password and session length
Home Chat Help Search Calendar Login Register
Pages: [1] 2
Print
Author Topic: Field definitions in News 2.6  (Read 1182 times)
0 Members and 1 Guest are viewing this topic.
ian72
Forum Member
*

Karma: 0
Offline Offline

Posts: 4


« on: 15 Nov 2007, 07:34 »

I'm a new user of CMSMS so go easy on me please!

I'm using News 2.6 and cannot get my custom field definitions to show up in the pages.

E.g I've added a field definition called Filename (set to public)
In my summary template I'm trying to call it like so
Code:
{$entry->filename}

but no show (I've tried Filename too).

Showing all page variables using
Code:
{$entry|print_r}
tells me the custom field is not in the list either!
Checking the database show the info and table data is being stored correctly.
I've cleared the cache too.

Anyone else had success adding field definitions? Can you show me too
Thanks in advance
Ian



Logged
streever
Forum Member
*

Karma: 2
Offline Offline

Posts: 249


« Reply #1 on: 15 Nov 2007, 19:07 »

Hi Ian,

that is surprising!

it works for me.

I wonder if this is a cache issue--OR--if you are calling the wrong template.

Please make sure you are calling the template that has that variable IN IT--and that the variable is within the {for each} commands!!

Can you post template here?

thanks
Logged
ian72
Forum Member
*

Karma: 0
Offline Offline

Posts: 4


« Reply #2 on: 16 Nov 2007, 04:30 »

hi streever,

I've tried clearing the cache to no avail.
In field definitions, I have a one called ImageCaption which is a Text Area and set to public. In my article I have put some text into that area.

In the detail template I have the following (copied from the original template)
Code:
{if isset($entry->fields)}

  {foreach from=$entry->fields item='field'}

{$field->name}: {eval var=$field->value}
     <div class="NewsSummaryField">
        {if $field->type == 'file'}
          <img src="{$entry->file_location}/{$field->value}/>
        {else}
          {$field->name}:&nbsp;{eval var=$field->value}
        {/if}
     </div>
  {/foreach}
{/if}

If I add
Code:
{$fields|print_r}
to print the variables, its shows
Code:
1

Have also tried using
Code:
{$entry->imagecaption}
but that shows nothing either.
Any ideas?
Thanks
Ian
Logged
cyberman
Support Team
Dev Team Member
Power Poster
*****

Karma: 139
Offline Offline

Posts: 6055

Location: Dohna / Germany


Reality.sys is corrupt. Reboot universe (Y/N)?


WWW
« Reply #3 on: 16 Nov 2007, 05:15 »

Showing all page variables

For that you can/should use the tag {get_template_vars}.
Logged

Für deutschsprachige Anwender / for german speaking users only
http://www.cmsmadesimple.de/ - die deutschsprachige Seite für CMSms
http://demo.cmsmadesimple.de/ - die Informationen der CMSms-Musterinstallation in deutsch
http://wiki.cmsmadesimple.org/index.php/Main_Page/de - deutschsprachiges CMSms-Wiki
http://dev.cmsmadesimple.org/projects/german/ - deutsche Sprachdateien für CMSms
cyberman
Support Team
Dev Team Member
Power Poster
*****

Karma: 139
Offline Offline

Posts: 6055

Location: Dohna / Germany


Reality.sys is corrupt. Reboot universe (Y/N)?


WWW
« Reply #4 on: 16 Nov 2007, 05:27 »

Have you made a look inside the sample summary template?

There must be something like this

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

And your new field will be added automatically Smiley ...
Logged

Für deutschsprachige Anwender / for german speaking users only
http://www.cmsmadesimple.de/ - die deutschsprachige Seite für CMSms
http://demo.cmsmadesimple.de/ - die Informationen der CMSms-Musterinstallation in deutsch
http://wiki.cmsmadesimple.org/index.php/Main_Page/de - deutschsprachiges CMSms-Wiki
http://dev.cmsmadesimple.org/projects/german/ - deutsche Sprachdateien für CMSms
ian72
Forum Member
*

Karma: 0
Offline Offline

Posts: 4


« Reply #5 on: 16 Nov 2007, 05:45 »

Yeah I did- it's exactly the same as I posted above!
Logged
cyberman
Support Team
Dev Team Member
Power Poster
*****

Karma: 139
Offline Offline

Posts: 6055

Location: Dohna / Germany


Reality.sys is corrupt. Reboot universe (Y/N)?


WWW
« Reply #6 on: 16 Nov 2007, 06:01 »

Works for me - please look here (the last news line)

http://test.cmsmadesimple.de/
Logged

Für deutschsprachige Anwender / for german speaking users only
http://www.cmsmadesimple.de/ - die deutschsprachige Seite für CMSms
http://demo.cmsmadesimple.de/ - die Informationen der CMSms-Musterinstallation in deutsch
http://wiki.cmsmadesimple.org/index.php/Main_Page/de - deutschsprachiges CMSms-Wiki
http://dev.cmsmadesimple.org/projects/german/ - deutsche Sprachdateien für CMSms
ian72
Forum Member
*

Karma: 0
Offline Offline

Posts: 4


« Reply #7 on: 16 Nov 2007, 06:14 »

I've just changed the config file to run in debug mode and I see this
Code:
Error (1146): Table 'website.cms_module_news_fieldvals' doesn't exist

My table has no prefix and  is callled
Code:
website.module_news_fieldvals

Having looked at the action.default.php I can see an error on line 280.

Code:
//
    // Handle the custom fields
    //
    $query3 = 'SELECT A.value,B.id,B.name,B.type FROM cms_module_news_fieldvals A, cms_module_news_fielddefs B WHERE A.fielddef_id = B.id AND B.public = 1 AND A.news_id = ? ORDER BY B.item_order';

I've changed it to:

Code:
//
    // Handle the custom fields
    //
    $query3 = 'SELECT A.value,B.id,B.name,B.type FROM '.cms_db_prefix().'module_news_fieldvals A, '.cms_db_prefix().'module_news_fielddefs B WHERE A.fielddef_id = B.id AND B.public = 1 AND A.news_id = ? ORDER BY B.item_order';


and all is now working.

Hope this helps someone else.
Thanks for your replies.



Logged
carasmo
Forum Member
*

Karma: 5
Offline Offline

Posts: 162


« Reply #8 on: 17 Nov 2007, 10:17 »

I've looked high and low for instructions on field definitions and I can't find anything except for some forum posts and I can't follow them since they appear to start somewhere in the middle.

I want to add a thumbnail image to the summary  and a larger image to the detail page. They may or may not be used, but it's good to have on hand. Is there a step by step instruction for people who are not technically adept. I'm not able to intuit this.

Thanks!
Logged
calguy1000
Posts that don't follow the rules (don't ask what the rules are, read them) will be ignored, moved or deleted
Dev Team Member
Power Poster
*****

Karma: 141
Offline Offline

Posts: 3461

Location: Calgary, Canada



WWW
« Reply #9 on: 17 Nov 2007, 10:35 »

1.  Go to the field definitions tab in News
     Create a new field definition called 'thumbnail' of type "file"
     Create another field definition called 'image' of type "file"

2. Go into the 'summary templates tab'
    Click 'add a new template'
    add:   {if isset($entry->thumbnail)}<img src="{$entry->file_location}/{$entry->thumbnail}"/>{/if}
    Give the new template a name
    Click submit

3.  Mark that template as default

4.  Go into the 'detail templates' tab
     Click 'add a new template'
     add:  {if isset($entry->thumbnail)}<img src="{$entry->file_location}/{$entry->image}"/>{/if}
     Give the new template a name
     Click submit

5.  Mark that template as default

6.  Add a couple of news articles with thumbnails and/or images for testing.

Now somewhere in your page template or page content, you should have a {news} tag.  If all worked well, you should see the thumbnail image in the summary view, and the full sized image in the detail view.  If not, do a view source on the output and make sure that the syntax is correct, I may have a typo in the above text.  If I do, you'll need to go back to the news admin and edit the templates that you created in the above steps.

You'll also want to add a <div> around each of the images, or a classname on the tag, set widths, alt tags, etc, etc, etc.
Logged

----
CMS Made Simple is Simple - For experienced developers.   You don't need to know php to use CMS but you should have some experience with website design, website development, and supporting dynamic applications in a hosted environment.   The words CSS, XHTML, and permissions should not be new to you.
carasmo
Forum Member
*

Karma: 5
Offline Offline

Posts: 162


« Reply #10 on: 17 Nov 2007, 10:51 »

YOU are the rocking-est ever! Thank you deeply and profoundly!
Logged
carasmo
Forum Member
*

Karma: 5
Offline Offline

Posts: 162


« Reply #11 on: 17 Nov 2007, 11:58 »

I followed it exactly and it didn't work. But I do get this at the top of the news entry page:

Invalid argument supplied for foreach() in /home/.scoundrel/domainuser/domain.com/modules/News/action.editarticle.php on line 141

141-168 looks like this:

Code:

foreach( $types as $onetype )
  {
$elem = $id.'customfield_'.$onetype['id'];
if( isset($_FILES[$elem]) &&
$_FILES[$elem]['name'] != '' )
  {
if( $_FILES[$elem]['error'] != 0 ||
$_FILES[$elem]['tmp_name'] == '')
  {
echo $this->ShowErrors($this->Lang('error_upload'));
$error = true;
  }
else
  {
$error = '';
$value = $this->handle_upload($articleid,$elem,$error);
if( $value === FALSE )
  {
echo $this->ShowErrors($error);
$error = true;
  }
else
  {
$params['customfield'][$onetype['id']] = $value;
  }
  }
  }
  }


Logged
Roberto
Forum Member
*

Karma: 0
Offline Offline

Posts: 24

Location: Sevilla - Andalucía



WWW
« Reply #12 on: 20 Nov 2007, 06:36 »

Hello carasmo,

I've the same warning, maybe this module doesn't work correctly using fields definition.

Have you eliminated this warning?

Roberto.
Logged
carasmo
Forum Member
*

Karma: 5
Offline Offline

Posts: 162


« Reply #13 on: 20 Nov 2007, 09:36 »

I can't figure it out.  Cry
Logged
dmccay
Forum Member
*

Karma: 1
Offline Offline

Posts: 1


« Reply #14 on: 01 Dec 2007, 06:39 »

I followed it exactly and it didn't work. But I do get this at the top of the news entry page:

Invalid argument supplied for foreach() in /home/.scoundrel/domainuser/domain.com/modules/News/action.editarticle.php on line 141

141-168 looks like this:

Code:

foreach( $types as $onetype )
  {
$elem = $id.'customfield_'.$onetype['id'];
if( isset($_FILES[$elem]) &&
$_FILES[$elem]['name'] != '' )
  {
if( $_FILES[$elem]['error'] != 0 ||
$_FILES[$elem]['tmp_name'] == '')
  {
echo $this->ShowErrors($this->Lang('error_upload'));
$error = true;
  }
else
  {
$error = '';
$value = $this->handle_upload($articleid,$elem,$error);
if( $value === FALSE )
  {
echo $this->ShowErrors($error);
$error = true;
  }
else
  {
f $params['customfield'][$onetype['id']] = $value;
  }
  }
  }
  }



Had the same issue and solved it by testing the $types array to see if it was empty.
This is a common problem in PHP so all you have to do is open the file called 'action.editarticle.php' and make the following changes.
Right before the line
Code:
foreach( $types as $onetype )
add the statement
Code:
if($types != 0){
and after the last closing bracket ADD another one to close out the If Statement.
The whole section should then look like this:
Code:
                     if($types != 0){
foreach( $types as $onetype )
  {
$elem = $id.'customfield_'.$onetype['id'];
if( isset($_FILES[$elem]) &&
$_FILES[$elem]['name'] != '' )
  {
if( $_FILES[$elem]['error'] != 0 ||
$_FILES[$elem]['tmp_name'] == '')
  {
echo $this->ShowErrors($this->Lang('error_upload'));
$error = true;
  }
else
  {
$error = '';
$value = $this->handle_upload($articleid,$elem,$error);
if( $value === FALSE )
  {
echo $this->ShowErrors($error);
$error = true;
  }
else
  {
$params['customfield'][$onetype['id']] = $value;
  }
  }
  }
    }
}
Logged
Pages: [1] 2
Print
Jump to: