Support Forums

Displaying variables and extra fields NOT already shown on the page

This is a discussion on Displaying variables and extra fields NOT already shown on the page within the Modules / Plugins / Modifications forums, part of the Developer Forums category; Tom, in short the best way to accomplish something is based on many factors beyond just your desired result. As ...


Go Back   68 Classifieds Forums > Developer Forums > Modules / Plugins / Modifications

Reply
 
Thread Tools Display Modes
Old 08-27-2010, 09:51 AM   #51
curmudgeon
 
Join Date: Mar 2006
Posts: 5,364
Rep Power: 135
Lhotch is a glorious beacon of light Lhotch is a glorious beacon of light Lhotch is a glorious beacon of light
Default

Tom,

in short the best way to accomplish something is based on many factors beyond just your desired result.

As someone new to 68C I can understand why you dont see the bigger picture but you also need to understand that many of the things you think dont matter are actually key issues in the decision process of how best to proceed.

As a developer we are constantly faced with these challenges, people think Oh he can write code this will be easy. Sometimes it is, sometimes is deceptivly complex but for those not in our shoes they take it for granted.

Now back to your 'problem', now that I know what we are dealing with the solution is not that difficult. As I have already stated, the extra fields are presented to the template as an array of data, the array is looped over and each item is checked to se if it has a value and if it does its displayed.

so, look a the debug console to see your extra fields.....

look at the viewlistoing.tpl template to see the section that loops over

PHP Code:
{* Extra Fields *}
            {foreach 
from=$extrafields item=extras}
            <
tr>
                <
td><strong>{$extras.title}:</strong></td>
                <
td>
                    {if isset(
$extras.value)}
                      {foreach 
key=key item=item from=$extras.value}
                        {
$item|nl2br}<br />
                        {
foreachelse}
                        {
$extras.value}
                      {/foreach}
                     {/if}
                </
td>
            </
tr>
            {/foreach}
            {* 
End Extra Fields *} 
Okay, so now you have an extra field called "List Type" or what ever you named it, its a dropdown list with fixed choices.

The template variable $extrafields is actually a multidimentional array or group of arrays within an array. The smarty foreach loop says that its going to break dow the $extrafields multidimensional array into single arrays and for each array its going to display values.

The first thing in the loop an table row is created, then a data cell to hold the title of the exta field. If you want to have your extra field called "list type" not to be displayed in the ad for the client to see then what would you do? You have 2 options, set the extra field to not be seen in the ad OR use logic to check for the extra field in the foreach and dont display it if its encountered. If you set the field to not be displayed then the data wont be there to evaluate against so I would probably opt for the later.

So now, if we are only concerned with the output and value of that one extra field and they are all being looped over, then all we have to do is ad a logic check in the existing loop to see if the current loop iteration is the extra field in question. Its important to note that the table row is created first after the foreach loop starts so if we dont want a row added if our "list type" extra field is encountered we would want to put the logic before the opening TR tag.....something like this...

PHP Code:
{* Extra Fields *}
            {foreach 
from=$extrafields item=extras}
{if 
$extras.title != "List Type"}
            <
tr>
                <
td><strong>{$extras.title}:</strong></td>
                <
td>
                    {if isset(
$extras.value)}
                      {foreach 
key=key item=item from=$extras.value}
                        {
$item|nl2br}<br />
                        {
foreachelse}
                        {
$extras.value}
                      {/foreach}
                     {/if}
                </
td>
            </
tr>
{/if}
            {/foreach}
            {* 
End Extra Fields *} 
So above3 all I did was say if the title of the current extra field being looped over IS NOT "List Type" then proceed, create the table row and data cells etc. That will allow all of your extra fields, regardless of how unique or many to be displayed by the list type field will not be.

Ok, but maybe you dont actually want to hide the field, just change the vale of the extra field depending on its current setting, thats simple enough to do by simply replacing the bottom {/if} I added with an else and then adding in your needed logic to look at the value of the drop down and output what is desired.


PHP Code:
{* Extra Fields *}
            {foreach 
from=$extrafields item=extras}
{if 
$extras.title != "List Type"}
            <
tr>
                <
td><strong>{$extras.title}:</strong></td>
                <
td>
                    {if isset(
$extras.value)}
                      {foreach 
key=key item=item from=$extras.value}
                        {
$item|nl2br}<br />
                        {
foreachelse}
                        {
$extras.value}
                      {/foreach}
                     {/if}
                </
td>
            </
tr>
{else}
<
tr>
                <
td><strong>{$extras.title}:</strong></td>
                <
td>
                    {if isset(
$extras.value)}
                      {foreach 
key=key item=item from=$extras.value}
                        {
$item|nl2br}<br />
                        {
foreachelse}

{if 
$extras.value == "Give Away"}
Free to Good Home.
{elseif 
$extras.value =="Sell"}
{
$price|format_money}
{/if}                        

                      {/foreach}
                     {/if}
                </
td>
            </
tr>
{/if]
            {/foreach}
            {* 
End Extra Fields *} 
__________________
Larry

Knowledge learned is more valuable than knowledge given.
Lhotch is offline   Reply With Quote
Old 08-28-2010, 05:02 AM   #52
Customer
 
Join Date: Aug 2010
Posts: 100
Rep Power: 5
T0m1 is on a distinguished road
Default

Hi Larry,

What can I say other than my sincerest thanks. I will give this a test today

Just to double check, where you have put "List Type" I need to insert the name of the field I gave it? Not the backend name but the regular name ?

I will let you know how everything goes and how I fair

Again very many thanks,

Tom.
__________________
Tom.

68c Developer v4.1.10 - Very Custom Template
MySQL v5.0.91-community <-> PHP v5.2.13 <-> Apache v2.2.15

Experience is the name we give to our mistakes
T0m1 is offline   Reply With Quote
Old 08-28-2010, 08:32 AM   #53
Customer
 
Join Date: Aug 2010
Posts: 100
Rep Power: 5
T0m1 is on a distinguished road
Default

Hi Larry,

I have given the above code a try. Unfortunately I am still only seeing the out as per the inbuilt list extra fields function...

It would seem it doesnt even get to your modified code before terminating as complete...

However, upon having reordered the foreacha dn if statements a little I have got it to display as expected.

I am unsure of the effects of doing so but, ive been able to "Split" your example into 2 seperate bits of code which allow me to place the price side of things with the price instead of bringing the price aspects down tot he extra fields are.

So I now have the following, for the price controlled areas;
PHP Code:
{* Custom Extra Field *}
            {foreach 
from=$extrafields item=extras}
                {if 
$extras.title == "Sale Type"}
                    <
tr>
                        <
td><strong>{$smarty.const.LANG_PRICE}:</strong></td>
                        <
td>
                            {if isset(
$extras.value)}
                            {foreach 
key=key item=item from=$extras.value}
                            {if 
$extras.value == "To Give Away"}
                            
Free to good home.
                            {elseif 
$extras.value == "Sell"}
                            {
$price|format_money} {get_extra_field id=$view fid=7}
                            {/if}
                            {/foreach}
                            {/if}
                            </
td>
                            </
tr>
                 {/if}
            {/foreach}
            {* 
End Custom Extra Field *} 
And then for the extra fields (have we had to set the "Sell, Give Away" one to show
PHP Code:
{* Extra Fields *}
            {foreach 
from=$extrafields item=extras}
{if 
$extras.title != "Sale Type"}
            <
tr>
                <
td><strong>{$extras.title}:</strong></td>
                <
td>
                    {if isset(
$extras.value)}
                      {foreach 
key=key item=item from=$extras.value}
                        {
$item|nl2br}<br />
                        {
foreachelse}
                        {
$extras.value}
                      {/foreach}
                     {/if}
                </
td>
            </
tr>
{/if}
            {/foreach}
            {* 
End Extra Fields *} 
This now (from first outlook) appears to be working like an absolute charm.

Many many many thanks for all your help. I definately wouldnt have been able to do this without you, thats for sure

Kindest regards,
__________________
Tom.

68c Developer v4.1.10 - Very Custom Template
MySQL v5.0.91-community <-> PHP v5.2.13 <-> Apache v2.2.15

Experience is the name we give to our mistakes

Last edited by T0m1; 08-28-2010 at 08:34 AM.
T0m1 is offline   Reply With Quote
Old 08-28-2010, 01:41 PM   #54
curmudgeon
 
Join Date: Mar 2006
Posts: 5,364
Rep Power: 135
Lhotch is a glorious beacon of light Lhotch is a glorious beacon of light Lhotch is a glorious beacon of light
Default

I figured you would probably end up with another loop over the extra fields up at the price but wasnt going to get that involved until you had a basic understanding of how to evaluate the current loop over extra fields.

Glad ya got it working.
__________________
Larry

Knowledge learned is more valuable than knowledge given.
Lhotch is offline   Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
MODIFICATION: Display your extra fields on the showlistings.tpl page cwp Modules / Plugins / Modifications 28 08-06-2009 01:42 PM
extra fields in featured ads on home page rockabilly Technical Support 3 07-01-2009 06:02 AM
Extra Fields Showing Up On Search Page hotchops Technical Support 6 04-30-2009 10:34 PM
Extra Fields On View Listing Page dexignz Technical Support 1 09-23-2008 10:01 AM
extra fields on show results page anna245 Technical Support 3 04-18-2008 02:31 PM


All times are GMT -4. The time now is 08:13 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2011, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0