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

merlinofchaos’s picture

Status: Active » Closed (works as designed)

When 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()

mossill’s picture

Component: Panel nodes » Plugins - contexts

I 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 ?

mossill’s picture

Priority: Normal » Critical
Status: Closed (works as designed) » Needs review

can 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']

???

merlinofchaos’s picture

Priority: Critical » Normal
Status: Needs review » Closed (won't fix)

Please don't ask the same questions in different issues. The answers don't change.

mossill’s picture

Here 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;

e-fee’s picture

I have the same problem but print_r(array_keys($contexts)); in my custom PHP code doesn't work, just produces an error message

warning: array_keys() [function.array-keys]: The first argument should be an array in /home/www/drupal6/includes/common.inc(1695) : eval()'d code on line 3.

print_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

The answers don't change.

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 with global $account, doesn't work here. So %user:uid would 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

Zalakain’s picture

Component: Plugins - contexts » Code

Hi, 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.

gthing’s picture

I'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.

gthing’s picture

Okay I was able to get it working like this:

$args = panels_get_current_page_display();
echo $args->args[0];

And you can find the proper index with :

print_r($args->args);
diwant’s picture

I 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.

apassi’s picture

#9 HC solution!!! GREAT!