{"id":420,"date":"2022-08-30T15:01:03","date_gmt":"2022-08-30T15:01:03","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/drupal-7-cck-feilds-deconstruction-from-content-in-node-tpl-php-file-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:01:03","modified_gmt":"2022-08-30T15:01:03","slug":"drupal-7-cck-feilds-deconstruction-from-content-in-node-tpl-php-file-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/drupal-7-cck-feilds-deconstruction-from-content-in-node-tpl-php-file-collection-of-common-programming-errors\/","title":{"rendered":"Drupal 7 CCK feilds deconstruction from $content in node.tpl.php file-Collection of common programming errors"},"content":{"rendered":"<p>After a long quest, finally I got the solution for splitting $content in Drupal 7 in node.tpl.php.<\/p>\n<p>Previously i was using i was using :-<\/p>\n<pre><code>print $node-&gt;field_name['und'][0]['value'];\n<\/code><\/pre>\n<p>Which was giving a warning :-<\/p>\n<pre><code>Notice: Undefined offset: 0 in include() (line 24 of C:\\xampp\\htdocs\\drup\\sites\\all\\themes\\myCustomTheme\\node.tpl.php)\n<\/code><\/pre>\n<p>Now I am using the function below which works fine with no errors<\/p>\n<pre><code>$output= field_get_items('node', $node, 'field_name');\n$output = $output[0]['safe_value'];\nprint $output;\n<\/code><\/pre>\n<p>Now the problem is I have more than 50 fields on the page , I don&#8217;t think it would be efficient to call field_get_items(&#8216;node&#8217;, $node, &#8216;field_name&#8217;) function 50 times.<\/p>\n<p>Whats the alternate ? OR should I strict to the field_get_items function OR should I strict to the print $node-&gt;field_name[&#8216;und&#8217;][0][&#8216;value&#8217;]; which I heard is not good to use in Drupal 7 as und is undefined. This though solves my problem but gives irritating warnings.<\/p>\n<ol>\n<li>\n<p>In your template you should have access to the variables that are preprocessed earlier.<\/p>\n<p>Each of your field is actually a variable so you can do $field_name[LANGUAGE_NONE][0][&#8216;safe_value&#8217;]<\/p>\n<p>To get rid of error notices, I suggest that you use the isset() function<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-09 19:12:06. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>After a long quest, finally I got the solution for splitting $content in Drupal 7 in node.tpl.php. Previously i was using i was using :- print $node-&gt;field_name[&#8216;und&#8217;][0][&#8216;value&#8217;]; Which was giving a warning :- Notice: Undefined offset: 0 in include() (line 24 of C:\\xampp\\htdocs\\drup\\sites\\all\\themes\\myCustomTheme\\node.tpl.php) Now I am using the function below which works fine with no [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-420","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/420","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=420"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/420\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=420"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=420"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=420"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}