Please can explain how to use "PHP Code Before Output" and "PHP Code After Output"?

Is there a way to access to the field content?
thanks

Comments

vegansupreme’s picture

field content is $content
Other variables that can be accessed are:

  • $x
  • $y
  • $h
  • $w

I think you can also access $border.
Additionally, you can use TCPDF and PHP functions.
For more info check out Views PDF Documentation under "Render Settings"

leonano’s picture

Thanks vegansupreme.
$content is the view of the field? In my case is a field collection, so has different fields into the content, can I access all value by $content->title for example? Or is the html result of the field formatter?
Let me explain:
I have a field collection and in PDF every field of this collection is printed with great space before and after.
I print out this collection on node with a panel view of 3 column, but is not possible with PDF?

vegansupreme’s picture

I believe it is the html result of the field formatter. To reduce that extra space, you could strip div tags under field rewriting. TCPDF doesn't always handle divs nicely.
As far as columns, this can be done, start reading around #21 #1345182: Positioning Field Output for Columns
Also If you want to experiment with 7.x-2.x you could try the branch in comment #75 I'm looking for feedback, thought it's still pretty rough.

sander-martijn’s picture

I came here because I assumed what vegansupreme said - but I don't think it's true. I did exactly that, but if I don't put tags around it then the field contents just become whatever is written (in my case as a test I am using "$content .= ' ' . $h;" which in theory should output the field plus the height. If I do I get nothing output and in the admin I'm seeing:

Notice: Undefined variable: h in eval() (line 2 of /path/site.com/modules/php/php.module(80) : eval()'d code).
Notice: Undefined variable: content in eval() (line 2 of /path/site.com/modules/php/php.module(80) : eval()'d code).

fyi what I'm hoping for is that the height will give me an indicator of whether the content has wrapped to two lines or not and adjust the positioning accordingly.

vegansupreme’s picture

You must check the 'bypass php_eval' checkbox and NOT use <?php tags for any of that to work. This was a "feature" that was introduced after those instructions were written.

$h is the height that's specified in the field position, if you leave that field blank, it will probably just be blank. I've yet to figure out auto height. You might be able to do what you need with $this->y instead.

killua99’s picture

Status: Active » Closed (outdated)