Closed (won't fix)
Project:
Panels
Version:
6.x-3.0
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
3 Oct 2009 at 21:07 UTC
Updated:
2 Aug 2013 at 13:18 UTC
How to use the "context keywords" inside "New Custom Content" I am using new Custom content with PHP i need to access to the %nodereference:nid in my PHP script with that value i will show the node on my panel.
Please help me i have spent days looking for a solution.
THANKS
Comments
Comment #1
merlinofchaos commentedWhen using the PHP filter, the context keyword replacements happen after PHP has run. So if you're trying to use this keyword in code, it won't work; it only works on the resulting output.
If, using PHP, you need access to the data provided by the contexts, try the function
panels_get_current_page_display()Comment #2
mossill commentedI don't understand ?
This is what panels 3 says in the "Selection Rules"
"All contexts will be available in the $contexts variable."
How can I access "Term:names" with this ?
Comment #3
mossill commentedcan someone please explain how to properly use the $context with in custom php ?
In what form will in be in ? There is no documentation for this question.
$contexts->term['name']
???
Comment #4
merlinofchaos commentedPlease don't ask the same questions in different issues. The answers don't change.
Comment #5
mossill commentedHere is your answer:
First run this to see your available values and structure:
print_r(array_keys($contexts));
A Simple way (can be done differently)
$object = $contexts['context_vocabulary_1'];
print $object->type;
Comment #6
e-fee commentedI have the same problem but
print_r(array_keys($contexts));in my custom PHP code doesn't work, just produces an error messageprint_r($contexts);doesn't show anything but I don't think it is empty.Or, WHERE to use this
panels_get_current_page_display()???Sometimes it could be very helpful to post not only these small tidbits of code but also to explain where they should be placed, so that also people are able to understand it who don't know every single function of thecode. At least I do, if I try to explain something to less experienced users. So if
this is fine but if someone still asks, or asks at another place, the answers might, although being correct, not have been sufficient for understanding the issue.
Well, here is what I want to do and at least I understand that my problems are caused by exactly that issue:
I want to show some content inside a custom pane (using Advanced Profile Kit) only if the user is NOT looking at his own profile. So I have to compare the uid of the acting user (got it via
global $user) with the uid of the user of the profile being shown.$account->uid, also withglobal $account, doesn't work here. So%user:uidwould be fine (and returns the correct value) but as you wrote above, I can't use it in my PHP code.So I need to get the content of that variable first. Any ideas?
Sonja
Comment #7
Zalakain commentedHi, this is an old one... but got a solution, just in case someone else is in need of it.
You have to create an additional Context to the ones the Panel might give you. Click on Context under your Variant, add the relevant one and make sure you save the variant once added.
Once done that, go back to your Content tab and when you attempt adding some Custom content, the substitution variables for your newly added Context will be there for you to play with in your PHP. Voila!
HTH.
Comment #8
gthing commentedI'm also looking for a solution here and have run into the same problem as #6.
#7s solution seems to be against the early post that variables will be available to php. I can't get variables to print in plain text, php, using the code above, nothing.
Comment #9
gthing commentedOkay I was able to get it working like this:
And you can find the proper index with :
Comment #10
diwant commentedI did what @gthing in 9 did. Only, the current panels page function gets you a lot of info and the arguments of the panel are present in what is returned as well as the arguments #9 print_r'd. Just thought I'd point out that you can get a lot about the current panel page display from that function.
Comment #11
apassi commented#9 HC solution!!! GREAT!