By Fagault Eric on Wednesday, 03 October 2018
Posted in General
Replies 8
Likes 0
Views 541
Votes 0
Hello,
I need to display the URL of the site specified in the "Website" field of a page.
To retrieve the value of a user's field, for example:
$ FriendAge = $ UserFriends-> getFieldValue ('BIRTHDAY');

How can I do for the URL mentioned in the URL field of a page?

Best ragard.

Eric
You can try this :

[gist type="php"]
// Retrieve your current Page id
$id = $this->input->get('id', 0, 'int');

// Page library
$page = ES::page($id);

// Retrieve the certain custom field from this Page data
// URL-URL is your custom field unique key
$customField = $page->getFieldValue('URL-URL');
echo $customField;exit;
[/gist]
·
Wednesday, 03 October 2018 18:53
·
0 Likes
·
0 Votes
·
0 Comments
·
Thank you very much Arlex,
I did that:
$ LID = JRequest :: getVar ('id', 0, '', 'int');
$ page = ES :: page ($ LID);
echo $ page-> getName ();

I will do as you say.

Best regards.

Eric
·
Wednesday, 03 October 2018 19:15
·
0 Likes
·
0 Votes
·
0 Comments
·
URL-URL does not work.
It works:
$ customField = $ page-> getFieldValue ('URL');
echo $ customField;

exit;
causes an error.
·
Wednesday, 03 October 2018 19:34
·
0 Likes
·
0 Votes
·
0 Comments
·
[gist type="php"]
$lid = JRequest::getVar('id', 0, '', 'int');
$page = ES::page($lid);
echo $page->getName();

$customField = $page->getFieldValue('URL');
echo $customField;
[/gist]

Do you mean when you run this code on your site, it hit some error? If yes, can you elaborate more details regarding this so I can better have a check?

1. Which PHP file you running this code?
2. Is it this $page variable return the correct page data if you var_dump($page)?
·
Thursday, 04 October 2018 10:33
·
0 Likes
·
0 Votes
·
0 Comments
·
Hello Arlex,

It's a small module that I just made.

There is no error, everything works fine with the code I made.

<? Php

$id = JRequest :: getVar ('id', 0, '', 'int');
// $id = $this-> input-> get ('id', 0, 'int');
$page = ES :: page ($id);
echo $page-> getName ();
?>


then


<a href="<?php echo $page-> getFieldValue ('URL');?> "target =" blank "class =" o-nav__link t-text - muted ">
<i class = "es-side-widget__icon fa fa-globe t-lg-mr - md"> </ i>
<? php echo $page-> getFieldValue ('URL'); ?>
</a>


But ('URL-URL') does not seem to match anything, when I use ('URL') it works.

Best regards.

Eric
·
Thursday, 04 October 2018 22:07
·
0 Likes
·
0 Votes
·
0 Comments
·
Oh, maybe i used wrong example so made you confuse, actually i used this 'URL-URL' as example is because my URL custom field unique name call 'URL-URL', you can check my screenshot here : http://take.ms/Tx6JH

So when you write this similar code $page->getFieldValue('URL'), inside the parameter value have to match with your custom field unique key.
·
Friday, 05 October 2018 10:22
·
0 Likes
·
0 Votes
·
0 Comments
·
View Full Post