Page 1 of 1
[solved] News detail templates not showing custom field data
Posted: Fri Dec 02, 2011 10:38 am
by jmires
Hi all,
I'm using CMSMS 1.10.2, and News 2.12.3
I'm actually not sure exactly when this started happening (upgrading to 1.10, 1.10.1, or 1.10.2), but News detail templates are not showing any custom field data.
So I have a custom field called "Article Author". In my detail template I have:
Code: Select all
{if $entry->article_author}
<div id="NewsPostDetailAuthor">
by {$entry->article_author}
</div>
{/if}
The data is being saved in the database just fine, showing up in back-end editing, etc. - just not showing up on the actual news detail page shown to visitors.
The same is true for another custom field.
Any ideas? Help is much appreciated.
----------------------------------------------
Cms Version:
1.10.2
Installed Modules:
CMSMailer:
2.0.2
FileManager:
1.2.0
MenuManager:
1.7.7
ModuleManager:
1.5.3
News:
2.12.3
Printing:
1.1.2
Search:
1.7
ThemeManager:
1.1.4
TinyMCE:
2.9.4
CGExtensions:
1.27.1
CGFeedMaker:
1.0.14
CGSimpleSmarty:
1.4.10
FormBuilder:
0.7.1
CMSSimplepie:
1.0
CGBlog:
1.7.6
Archiver:
0.2.4
SiteMapMadeSimple:
1.2.5
CMSPrinting:
1.0
Config Information:
php_memory_limit:
process_whole_template:
false
output_compression:
false
max_upload_size:
2000000
default_upload_permission:
664
url_rewriting:
mod_rewrite
page_extension:
query_var:
page
image_manipulation_prog:
GD
auto_alias_content:
true
locale:
default_encoding:
utf-8
admin_encoding:
utf-8
set_names:
false
Php Information:
phpversion:
5.2.17
md5_function:
On (True)
gd_version:
2
tempnam_function:
On (True)
magic_quotes_runtime:
Off (False)
E_STRICT:
0
memory_limit:
64M
max_execution_time:
30
output_buffering:
On
safe_mode:
Off (False)
file_uploads:
On (True)
post_max_size:
12M
upload_max_filesize:
10M
session_save_path:
/tmp (1777)
session_use_cookies:
On (True)
xml_function:
On (True)
Server Information:
Server Api:
cgi
Server Db Type:
MySQL (mysql)
Server Db Version:
5.0.92
----------------------------------------------
Re: News detail templates not showing custom field data
Posted: Fri Dec 02, 2011 10:46 am
by RonnyK
I just checked, and as far as I see is the field showing up.
Did you tick the 'public'-field for the custom-field? As without that tick, it wont show at the frontend.
Ronny
Re: News detail templates not showing custom field data
Posted: Fri Dec 02, 2011 3:31 pm
by jmires
Yes, the fields are marked public.
Interestingly, this only appears to affect the use of custom fields within the news detail templates.
We are using the News module to also display random testimonials in the sidebar, so we have some custom News fields like Testimonial title, Testimonial Name, etc. - these all show up fine, including the sidebars of News detail pages where the other custom fields are not showing at all in the main content area.
We haven't changed the news detail templates (or other templates) in ages, so it appears to have been caused by one of our recent CMSMS upgrades.
Re: News detail templates not showing custom field data
Posted: Sun Dec 04, 2011 10:10 pm
by spcherub
Just for kicks, try the following in your template:
and see exactly how the custom fields are being referenced. A recent upgrade may have changed the way these fields are exposed in the template.
Hope this helps.
-S
Re: News detail templates not showing custom field data
Posted: Sun Dec 04, 2011 11:55 pm
by jmires
spcherub,
Thanks for the suggestion - that did lead me to see that for detail templates, the custom fields are not being put in $entry the same way.
So for a summary, template {$entry|@print_r} gives something like:
Code: Select all
stdClass Object
(
[author_id] => 4
[author] => jon
[authorname] => Jon
[id] => 154
[title] => Testimonal 9
[content] => You've transformed our family tremendously!
[summary] =>
[postdate] => 2010-01-11 16:18:36
[startdate] => 2010-01-11 16:18:36
[enddate] =>
[create_date] => 2010-01-11 16:19:19
[modified_date] => 2010-02-17 11:40:29
[category] => Testimonials
[testimonial_title] => Mother of Three
[testimonial_location] => San Francisco, California
[fieldsbyname] => Array
(
[testimonial_title] => stdClass Object
(
[value] => Mother of three
[id] => 9
[name] => Testimonial Title
[type] => textbox
)
[testimonial_location] => stdClass Object
(
[value] => San Francisco, California
[id] => 11
[name] => Testimonial Location
[type] => textbox
)
)
[fields] => Array
(
[0] => stdClass Object
(
[value] => Mother of three
[id] => 9
[name] => Testimonial Title
[type] => textbox
)
[1] => stdClass Object
(
[value] => San Francisco, California
[id] => 11
[name] => Testimonial Location
[type] => textbox
)
)
[file_location] => http://dev.mydomain.org/uploads/news/id154
[link] => http://dev.mydomain.org/news/154/64/Testimonal-9
[titlelink] => Testimonal 9
[morelink] => More
[moreurl] => http://dev.mydomain.org/news/154/64/Testimonal-9
)
1
Notice how just before "fieldsbyname" are the shorthand values for the custom fields (testimonial_title and testimonial_location) as accessed by the template with
Contrast that with the output of {$entry|@print_r} for our detail template:
Code: Select all
news_article Object
(
[_rawdata:private] => Array
(
[id] => 4
[category_id] => 4
[title] => Sibling Solutions
[content] => This is the article content
[postdate] => 2009-06-02 16:54:06
[summary] =>
[startdate] => 2009-06-02 16:54:06
[enddate] =>
[status] => published
[create_date] => 2009-06-02 16:55:46
[modified_date] => 2010-10-12 17:00:57
[author_id] => 1
[extra] =>
[news_url] =>
[fieldsbyname] => Array
(
[Article Author] => news_field Object
(
[_data:private] => Array
(
[value] => John Doe
[id] => 6
[name] => Article Author
[type] => textarea
)
)
)
)
[_meta:private] => Array
(
[returnid] => 64
[canonical] => http://dev.mydomain.org/news/4/64/Sibling-Solutions
)
[_inparams:private] => Array
(
[assign] => capturedcontent
[articleid] => 4
[returnid] => 64
[junk] => Sibling-Solutions
[action] => defaulturl
[inline] =>
[module] => News
)
[_inid:private] => cntnt01
)
1
Here I'm trying to access the Article Author custom field with
which obviously isn't working because it's not exposed in that way, even though the data is available in the fieldsbyname array. I also notice that the "fields" array is not present in the detail template one, but is in the summary template one.
Any ideas on how to proceed from here?
Re: News detail templates not showing custom field data
Posted: Mon Dec 05, 2011 1:49 am
by spcherub
Actually, it turns out the things have changed quite a bit in the News module (for the details template).
Quick answer - In your case, try the following:
Code: Select all
{if isset($entry->fields)}
{foreach from=$entry->fields item='field'}
{if $field->name == "Article Author"}
<div id="NewsPostDetailAuthor">
by {$field->value}
</div>
{/if}
{/foreach}
{/if}
I know this is kind of roundabout but it should work - if I find a better way to access the field directly I will let you know.
Longer answer - the following information was in the default News template with the new News module:
In previous versions of News the 'object' returned in $entry was quite simple, and a <pre>{$entry|@print_r}</pre> would output all of the available data
This has changed in News 2.12, the object is not quite as 'simple' as it was in previous versions, and that method will no longer work. Hence, below
you will find a referennce to the available data.
====
news_article Object Reference
====
Members:
--
Members can be displayed by the following syntax: {$entry->membername} or assigned to another smarty variable using {assign var='foo' value=$entry->membername}.
The following members are available in the entry array:
id (integer) = The unique article id.
author_id (integer) = The userid of the author who created the article. This value may be negative to indicate an FEU userid.
title (string) = The title of the article.
summary (text) = The summary text (may be empty or unset).
extra (string) = The "extra" data associated with the article (may be empty or unset).
news_url (string) = The url segment associated with this article (may be empty or unset).
postdate (string) = A string representing the news article post date. You may filter this through cms_date_format for different display possibilities.
startdate (string) = A string representing the date the article should begin to appear. (may be empty or unset)
enddate (string) = A string representing the date the article should stop appearing on the site (may be empty or unset).
category_id (integer) = The unique id of the hierarchy level where this article resides (may be empty or unset)
status (string) = either 'draft' or 'published' indicating the status of this article.
author (string) = The username of the original author of the article. If the article was created by frontend submission, this will attempt to retrieve the username from the FEU module.
authorname (string) = The full name of the original author of the website. Only applicable if article was created by an administrator and that information exists in the administrators profile.
category (string) = The name of the category that this article is associated with.
canonical (string) = A full URL (prettified) to this articles detail view using defaults if necessary.
fields (associative) = An associative array of field objects, representing the fields, and their values for this article. See the information below on the field object definition. In past versions of News this was a simple array, now it is an associative one.
customfieldsbyname = (deprecated) - A synonym for the 'fields' member
fieldsbyname = (deprecated) - A synonym for the 'fields' member
useexp (integer) = A flag indicating wether this article is using the expiry information.
file_location (string) = A url containing the location where files attached the article are stored... the field value should be appended to this url.
====
news_field Object Reference
====
The news_field object contains data about the fields and their values that are associated with a particular news article.
Members:
--------
id (integer) = The id of the field definition
name (string) = The name of the field
type (string) = The type of field
max_length (integer) = The maximum length of the field (applicable only to text fields)
item_order (integer) = The order of the field
public (integer) = A flag indicating wether the field is public or not
value (mixed) = The value of the field.
Re: News detail templates not showing custom field data
Posted: Mon Dec 05, 2011 3:26 am
by spcherub
You can also do (simpler):
Code: Select all
{assign var=index value="Article Author"}
{if $entry->fields.$index->value != ''}
<div id="NewsPostDetailAuthor">
by {$entry->fields.$index->value}
</div>
{/if}
You need the first assign as you have a space in your custom field name.
Hope that helps.
-S
Re: News detail templates not showing custom field data
Posted: Mon Dec 05, 2011 7:21 pm
by jmires
spcherub, thank you so much! that works like a charm, and thanks for pointing me to the default News detail template so I can see why. Very very much appreciated!
Re: [solved] News detail templates not showing custom field
Posted: Fri Dec 16, 2011 3:19 pm
by applejack
This is really stupid as it now breaks all the sites where any custom fields where accessed directly by their name. It still works in the summary template so why change it in the detail template. This should have been flagged up in a change log.
Re: [solved] News detail templates not showing custom field
Posted: Mon Apr 23, 2012 7:19 am
by kendo451
I think you guys are confusing the subject here.
$entry->fieldsbyname is not a synonym for $entry->fields
The difference is this:
$entry->fields has a standard numerical array index. So if you only have one custom field it will always have an index of 0, and you can access its value like this:
$entry->fields.0->value
If you have a field named "Article Author" it will be converted to lower case and space replaced with underscore. The way to access it by its name is like this:
$entry->fieldsbyname.article_author->value