Display Field along with some html

armaclans

Member
I have a some curious questions here,

Is it possible to have HTML activated when a custom field is active?

For example:
If there is a custom field, and the user puts something in that field and submits changes,
when that field goes to show on the website on details page, could I have a <div> wrapping it? but when the user decides to put nothing in that custom field both the <div> and the field disappear (not visible on details page)


Also is there a way I can make a plugin that shows certain content on certain pages, for example show "paragraph" in sidebar on details page but hide "paragraph" on homepage, etc..


Thank you for your time!
 

Mark

Administrator
Staff member
yes this is all possible, but you will need to know some basic PHP in order to create your own.
 

armaclans

Member
Do you have tips to where I can learn about this?

Im guessing it will be a

If field is 'full/used' {

display 'content'

else{

show nothing

}
 

Mark

Administrator
Staff member
that is correct, you are on the right track.

There is a tutorial in the tutorials section "how to create a plugin" that should help you
 

armaclans

Member
Ok, so reading some php I think I understand,

Correct me if I am wrong, I need to create a script that goes to the database to check if 'field' is empty. If this is true, the php can be told to display 'content'

My only question is how will the php know to check the database for the right user, since there are multiple details pages? if that makes sense...
 

Mark

Administrator
Staff member
you will use $username or $TMPL['username'] in your database query to make sure you get the right user data.
 

Mark

Administrator
Staff member
look at sources/details.php the code is fairly self explanatory, also look at some other plugins that might have similar functions.
 
Last edited by a moderator:

Basti

Administrator
Staff member
Little hint, after youve set up basic plugin requirements as in the tutorial. If your custom field name is acf_testfield

in php tmpl tags, are defined as $TMPL['acf_testfield'] ( not same as in html file )

so if you wanna show data on stats with a div, use details_compile_details.php . As Mark metioned you find possible hook names in the corresponding core php file, in this case details.php
We use this hook, because all member data is already selected and you not need to query database just for this.

Now in the file just check if the tmpl tag is empty. If not, set up a new tmpl tag which contain the div + custom field data
Code:
if (!empty($TMPL['acf_testfield']))
{
    $TMPL['my_new_tag'] = "<div>{$TMPL['acf_testfield']}</div>";
}
now you can place {$my_new_tag} on stats.html and it only show div only if it has some data
 

armaclans

Member
Ok, I have tried this via plug in and cannot get it to work..


When I upload the plugin, I have made sure the
Code:
{$acf_googlelink}
matches with the tag in the custom join field

on the details page, I added the new code
Code:
{$googlelinkcorrected}
So now if I leave the field empty, the field just shows up blank when viewing... shouldn't it be displaying 'EMPTY"



I have also tried the following code:

Code:
if (!empty($TMPL['acf_googlelink'])) {
 
 
} else {
 
    $TMPL['googlelinkcorrected'] = "<a href="{$TMPL['acf_googlelink']}">Google+ Link</a>";
}
this does not work either...
 

Attachments

Basti

Administrator
Staff member
You used
{$googlelinkcorrected} in stats.html?

Cause in the php i see $TMPL['newgooglelink']

The code is correct what you have in the file.
Code:
if (!empty($TMPL['acf_googlelink']))
{
    $TMPL['newgooglelink'] = "EMPTY";
}
This says, if the member filled out ( !empty = not empty ), {$newgooglelink} will display the text EMPTY
 

armaclans

Member
Ok,

New code, still does not work.

in stats.html i have placed the following code:

Code:
<li class="list-group-item">{$newgooglelink}</li>

in my plugin, here is the file structure:




Here is what details_compile_details.php states:

Code:
if (!empty($TMPL['acf_googlelink']))
{
} else {
    $TMPL['newgooglelink'] = "<a href="#">Testing</a>";
}



The list item still comes up blank....
 

Basti

Administrator
Staff member
$TMPL['newgooglelink'] = "<a href="#">Testing</a>";
This would trigger a php error, double quotes within doubles quotes are wrong

Either use double quotes in the html ( and surrounded by single quotes )
Code:
$TMPL['newgooglelink'] = '<a href="#">Testing</a>';
Or if you use all double quotes, you need to escape the inner one like this
Code:
$TMPL['newgooglelink'] = "<a href=\"#\">Testing</a>";
And just to clarify again, right you your link would show only if the member have nothing in acf_googlelink
Code:
if (!empty($TMPL['acf_googlelink']))
{
    // Member have filled out acf_googlelink
} else {
    // acf_googlelink is empty
    $TMPL['newgooglelink'] = "<a href="#">Testing</a>";
}
 

armaclans

Member
The code states, if the field is not filled out, Display nothing ELSE if the field is filled out display link "testing"


I tried

Code:
if (!empty($TMPL['acf_googlelink']))
{
// Member have filled out acf_googlelink
} else {
// acf_googlelink is empty
$TMPL['newgooglelink'] = '<a href="#">Testing</a>';
}

just for testing purposes, I have also tried the following code.. Which would mean if the field is empty, display "testing"

Code:
if (!empty($TMPL['acf_googlelink']))
{
$TMPL['newgooglelink'] = "Testing";

}
and still nothing shows.

I have double checked that the custom field has the acf_googlelink tag... and I have checked to make sure {$newgooglelink} is placed in stats.html...

I have also tried with the field being filled out, and not filled out on all code
 
Last edited:

Basti

Administrator
Staff member
The code states, if the field is not filled out, Display nothing ELSE if the field is filled out display link "testing"
No, like i said some posts ago, that is wrong thinking ... !empty means it is filled out

empty() = field is empty, !empty() = field is filled out ( ! signs meant NOT in php ), making this code the one you want, like i said before
Code:
if (!empty($TMPL['acf_googlelink']))
{
     // Member have filled out acf_googlelink
     $TMPL['newgooglelink'] = '<a href="'.$TMPL['acf_googlelink'].'">Google+</a>';
} else {
    // acf_googlelink is empty
     $TMPL['newgooglelink'] = 'Member not provided a google+ link';
}
Just to made sure, i pasted this on our dev list and it worked without any issues.

So the problems lays somewhere on your end. Most likely scenaria...
Are you editing the correct file?

skins/yourskin/stats.html
If you edit that file but the same file exist also in the "child" folder, then you edit the wrong one. If any file exist in child folder, that is the one you have to edit
 
Top