Page 1 of 2
Field definitions in News 2.6
Posted: Thu Nov 15, 2007 1:34 pm
by ian72
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
but no show (I've tried Filename too).
Showing all page variables using
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
Re: Field definitions in News 2.6
Posted: Fri Nov 16, 2007 1:07 am
by streever
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
Re: Field definitions in News 2.6
Posted: Fri Nov 16, 2007 10:30 am
by ian72
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: Select all
{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}: {eval var=$field->value}
{/if}
</div>
{/foreach}
{/if}
If I add
to print the variables, its shows
Have also tried using
but that shows nothing either.
Any ideas?
Thanks
Ian
Re: Field definitions in News 2.6
Posted: Fri Nov 16, 2007 11:15 am
by cyberman
ian72 wrote:
Showing all page variables
For that you can/should use the tag {get_template_vars}.
Re: Field definitions in News 2.6
Posted: Fri Nov 16, 2007 11:27 am
by cyberman
Have you made a look inside the sample summary template?
There must be something like this
Code: Select all
{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}: {eval var=$field->value}
{/if}
</div>
{/foreach}
{/if}
And your new field will be added automatically

...
Re: Field definitions in News 2.6
Posted: Fri Nov 16, 2007 11:45 am
by ian72
Yeah I did- it's exactly the same as I posted above!
Re: Field definitions in News 2.6
Posted: Fri Nov 16, 2007 12:01 pm
by cyberman
Works for me - please look here (the last news line)
http://test.cmsmadesimple.de/
[RESOLVED]: Field definitions in News 2.6
Posted: Fri Nov 16, 2007 12:14 pm
by ian72
I've just changed the config file to run in debug mode and I see this
Code: Select all
Error (1146): Table 'website.cms_module_news_fieldvals' doesn't exist
My table has no prefix and is callled
Having looked at the action.default.php I can see an error on line 280.
Code: Select all
//
// 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: Select all
//
// 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.
Re: Field definitions in News 2.6
Posted: Sat Nov 17, 2007 4:17 pm
by carasmo
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!
Re: Field definitions in News 2.6
Posted: Sat Nov 17, 2007 4:35 pm
by calguy1000
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)}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)}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 around each of the images, or a classname on the tag, set widths, alt tags, etc, etc, etc.
Re: Field definitions in News 2.6
Posted: Sat Nov 17, 2007 4:51 pm
by carasmo
YOU are the rocking-est ever! Thank you deeply and profoundly!
Re: Field definitions in News 2.6
Posted: Sat Nov 17, 2007 5:58 pm
by carasmo
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: Select all
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;
}
}
}
}
Re: Field definitions in News 2.6
Posted: Tue Nov 20, 2007 12:36 pm
by Roberto
Hello carasmo,
I've the same warning, maybe this module doesn't work correctly using fields definition.
Have you eliminated this warning?
Roberto.
Re: Field definitions in News 2.6
Posted: Tue Nov 20, 2007 3:36 pm
by carasmo
I can't figure it out.

SOLVED Re: Field definitions in News 2.6
Posted: Sat Dec 01, 2007 12:39 pm
by dmccay
carasmo wrote:
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: Select all
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
add the statement
and after the last closing bracket ADD another one to close out the If Statement.
The whole section should then look like this:
Code: Select all
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;
}
}
}
}
}