Field definitions in News 2.6

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
ian72
New Member
New Member
Posts: 4
Joined: Thu Nov 15, 2007 1:16 pm

Field definitions in News 2.6

Post 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

Code: Select all

{$entry->filename}
but no show (I've tried Filename too).

Showing all page variables using

Code: Select all

{$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
streever

Re: Field definitions in News 2.6

Post 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
ian72
New Member
New Member
Posts: 4
Joined: Thu Nov 15, 2007 1:16 pm

Re: Field definitions in News 2.6

Post 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

Code: Select all

{$fields|print_r}
to print the variables, its shows

Code: Select all

1
Have also tried using

Code: Select all

{$entry->imagecaption}
but that shows nothing either.
Any ideas?
Thanks
Ian
cyberman

Re: Field definitions in News 2.6

Post by cyberman »

ian72 wrote: Showing all page variables
For that you can/should use the tag {get_template_vars}.
cyberman

Re: Field definitions in News 2.6

Post 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 :) ...
ian72
New Member
New Member
Posts: 4
Joined: Thu Nov 15, 2007 1:16 pm

Re: Field definitions in News 2.6

Post by ian72 »

Yeah I did- it's exactly the same as I posted above!
cyberman

Re: Field definitions in News 2.6

Post by cyberman »

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

http://test.cmsmadesimple.de/
ian72
New Member
New Member
Posts: 4
Joined: Thu Nov 15, 2007 1:16 pm

[RESOLVED]: Field definitions in News 2.6

Post 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

Code: Select all

website.module_news_fieldvals
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.
carasmo
Power Poster
Power Poster
Posts: 506
Joined: Thu Feb 08, 2007 6:11 pm
Location: Florida

Re: Field definitions in News 2.6

Post 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!
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: Field definitions in News 2.6

Post 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.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
carasmo
Power Poster
Power Poster
Posts: 506
Joined: Thu Feb 08, 2007 6:11 pm
Location: Florida

Re: Field definitions in News 2.6

Post by carasmo »

YOU are the rocking-est ever! Thank you deeply and profoundly!
carasmo
Power Poster
Power Poster
Posts: 506
Joined: Thu Feb 08, 2007 6:11 pm
Location: Florida

Re: Field definitions in News 2.6

Post 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;
						  }
					  }
				  }
			  }


Roberto
Forum Members
Forum Members
Posts: 24
Joined: Thu Oct 25, 2007 6:37 pm

Re: Field definitions in News 2.6

Post 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.
carasmo
Power Poster
Power Poster
Posts: 506
Joined: Thu Feb 08, 2007 6:11 pm
Location: Florida

Re: Field definitions in News 2.6

Post by carasmo »

I can't figure it out.  :'(
dmccay

SOLVED Re: Field definitions in News 2.6

Post 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

Code: Select all

foreach( $types as $onetype )
add the statement

Code: Select all

 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: 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;
						  }
					  }
				  }
			    }
			}
Post Reply

Return to “Modules/Add-Ons”