How to theme an element of an array? - drupal

I have this array in a Drupal 7 installation, it outupts the term list that belongs to a specific vocabulary id:
<?php print render($content['taxonomy_vocabulary_3']); ?>
Now, what this does it outputs the result in a list, I would like to output it in a comma separated line.
Now, I suppose that I could do that with a foreach statement?
I´ve tried this, after reading the documentation, but it outputted nothing:
foreach($taxonomy_vocabulary_3 as $id=>$tag) {
echo "$tag, " ;
}
I´ve looked into what the Devel module told me about that array, and it showed me this:
taxonomy_vocabulary_3 (Array, 1 element)
und (Array, 2 elements)
0 (Array, 1 element)
tid (String, 3 characters ) 141
1 (Array, 1 element)
tid (String, 3 characters ) 320
But as you can see it shows the term id in each case, and not the term name...
What do you suggest? Thanks!!

You can load the term and then print it's title.
foreach($vocabulary as $tid) {
$term = taxonomy_term_load($tid);
// print whatever you want from this object.
print $term->title . ', ';
}
taxonomy_term_load

What you got is a build array - so that means that
$content['taxonomy_vocabulary_3']['#theme']
will be the theme function used to render the vocabulary. If you want to change the output you have two good solutions.
override the standard theme function in your theme - this will alter the output of all the calls to that theme function - in this case how all vocabularies is rendered.
Change the #theme value to a theme function of your liking - this could be a custom theme function you define in your theme.
For help on how to render the terms, you can take a look at how the original theme function is implemented - you can look it up at the Drupal API documentation.

Related

How to multiply a value, returned by a shortcode in Wordpress?

So I can't get my head around this. I am basically using a plugin that has the following shortcode
Example: [valueABC] which is equal to 40.
Now I want to multiply the value by 2, so the output with be 40*2 = 80 on the frontend. But can't figure out how to do it without hard coding it in PHP.
Try This:
function vx_summation(){
$vxtr=10;
return $vxtr;
}
add_shortcode('summation_shortcode','vx_summation');
function vx_preview_summation(){
$vxtr = do_shortcode('[summation_shortcode]');
return $vxtr*3;
}
add_shortcode('preview_summation_shortcode','vx_preview_summation');
[preview_summation_shortcode]
OR you can Follow this Documentation:
https://developer.wordpress.org/reference/functions/do_shortcode/

Filemaker Pro - Using Script to populate report layout

I have a problem where I have a list of fields from a table (not static, can be modified by user), and I need to generate a report using these user selected fields. The report can show all the rows, no need for aggregation or filtering.
I thought I could create a report layout then using a filemaker script to populate it but can't seem to find the right commands, can someone let me know how I could achieve this?
I'm using filemaker pro 18 advanced
Thanks in advance!
EDIT: Since you want a dynamic report, then I recommend you look up a technique called "Virtual List" for rendering the data.
Here's an example script that iterates over a found set of records and builds the virtual list data in a variable (it doesn't show how to render it though):
# Field names and delimiter
Set Variable [ $delim ; Value: Char(9) // tab character ]
# Set these dynamically with a script parameter
Set Variable [ $fields ; Value: List ( "Contacts::nameFirst" ; "Contacts::nameCompany" ; "Contacts::nameLast" ) ]
Set Variable [ $fieldCount ; Value: ValueCount ( $fields ) ]
Go to Layout [ “Contacts” (Contacts) ; Animation: None ]
Show All Records
Go to Record/Request/Page [ First ]
# Loop over all the records and append a row in the $data variable for each
Set Variable [ $data ; Value: "" ]
Loop
# Get the delimited field values
Set Variable [ $i ; Value: 0 ]
Set Variable [ $row ; Value: "" ]
Loop
Exit Loop If [ Let ( $i = $i + 1 ; $i > $fieldCount ) ]
Set Variable [ $value ; Value: GetField ( GetValue ( $fields ; $i ) ) ]
Insert Calculated Result [ Target: $row ; If ( $i > 1 ; $delim ) & $value ]
End Loop
enter code here
# Append the new row of data to the list variable
Insert Calculated Result [ Target: $data ; If ( Get ( RecordNumber ) > 1 ; ¶ ) & $row ]
Go to Record/Request/Page [ Next ; Exit after last: On ]
End Loop
# Save to a global variable to show in a virtual list layout
Set Variable [ $$DATA ; Value: $data ]
Exit Script [ Text Result: ]
please note this code is just one of many possible formats the virtual list can take. A lot of people, myself included, prefer to use JSON objects or arrays for each row of the list since it automatically handle field values with carriage returns. This is sort of the old-fashioned way. Kevin Frank at FileMaker Hacks has some good recent articles about virtual list techniques if you're interested.
PS, another great technique for rendering table data dynamically is to collect the data in a JSON array and render it in a webviewer with https://datatables.net/
I did something like this for the oncology department of UM om 1980 or so using 4th Dimension and a new plug in that used one line of code to create a web browser with all the functions that a doctor might want. The data was placed inside a variable as it was sent/returned and 4D could use a variable in the report to display the data.
FileMaker does not have this ability built in as 4D did so you will have to do it yourself.JSON is the most likely tool that I am familiar with. YouTube has many videos on JSON.
You have two classes of variables for your report: Column headers and column data to display. Fortunately Filemaker is quite good and very easy to design. Just make a typical report and replace the text/header or field names with a JSON variable or any. $ColumnName = JSON variable.
Create a JSON calculated field in the database. In that calculated field set the JSON variable and this can be used for all of the columns.
This is the essence of the idea with the final result to be determined by you. What you are asking for is not easy and would require serious work by a skilled JSON scripter.

Using != equals in php to remove unwanted activities rather than include the long list of wanted ones

I have a buddypress site and I have edited the activity stream to include the activities I want to see however it's more logical to filter out the unwanted so future plugins don't have to be manually included I have tried != but does not work.
<?php if ( bp_has_activities( bp_ajax_querystring( 'activity' ).'&action=bbp_reply_create,last_activity,gmw_location,activity_liked,rtmedia_update,new_avatar,updated_profile,joined_group,new_blog_post,bbp_topic_create,created_group' ) ) : ?>
And here is what I tried.
<?php if ( bp_has_activities( bp_ajax_querystring( 'activity' ).'&action!=friendship_created,new_member' ) ) : ?>
But the attempt simply left the whole stream blank.
I've never used Buddypress, but from what I see you cannot simply use the != operator. You are placing the != in a string that is the input for a function named bp_ajax_querystring(). From the function's name, and the rest of the input, it looks like a set of GET parameters.
GET parameters only allow the setting of attributes (so != has no meaning). Instead, place the ! in front of the expression being evaluated by the if statement:
if ( !bp_has_activities( bp_ajax_querystring( 'activity' ).'&action=bbp_reply_create,last_activity,gmw_location,activity_liked,rtmedia_update,new_avatar,updated_profile,joined_group,new_blog_post,bbp_topic_create,created_group' )

[wordpress]A shortcode that returns a shortcodes combo

I often use a combination of shortcodes to produce a line of three images. I'd like to simplify the process by creating an other shortcode that would nest the combination. Here's my code :
// [imgs img1='' img2='' img3='' height='150']
$output = '[row][col span="1/3"]
[ux_banner bg="'.$url1.'" height="'.$height.'"][/ux_banner]
[/col][col span="1/3"]
[ux_banner bg="'.$url2.'" height="'.$height.'"][/ux_banner]
[/col][col span="1/3"]
[ux_banner bg="'.$url3.'" height="'.$height.'"][/ux_banner]
[/col][/row]';
return do_shortcode($output) ;
So... well... it doesn't work. I'm a little bit confused about the nested possibilities of do_short_code. Any idea to fix my shortcode ?
Thank you !

Parsing images via nokogiri and xpath

I currently have a piece of code which will grab a product title, description, and price and for that it works great. However, I also need it to get the image URL which is where my dilemma is. I tried using a xpath inside the loop I have at the bottom and it lists out ALL the images that are equal to 220 on EVERY product which I dont want at all. So basically I get something like this....
product 1 Title here
product 1 Description here
product 1 price here
http://www.test.com/product1.jpg
http://www.test.com/product2.jpg
http://www.test.com/product3.jpg
http://www.test.com/product4.jpg
product 2 Title here
product 2 Description here
product 2 price here
http://www.test.com/product1.jpg
http://www.test.com/product2.jpg
http://www.test.com/product3.jpg
http://www.test.com/product4.jpg
Where as I obviously want product 1 to just have http://www.test.com/product1.jpg and product 2 to have http://www.test.com/product2.jpg etc, etc. The images are just in a div tag with no class or ID hence why I didnt just easily put them into a css selector. Im really new to ruby/nokogiri so any help would be great.
require 'nokogiri'
require 'open-uri'
url = "http://thewebsitehere"
data = Nokogiri::HTML(open(url))
products = data.css('.item')
products.each do |product|
puts product.at_css('.vproduct_list_title').text.strip
puts product.at_css('.vproduct_list_descr').text.strip
puts product.at_css('.price-value').text.strip
puts product.xpath('//img[#width = 220]/#src').map {|a| a.value }
end
Try changing:
puts product.xpath('//img[#width = 220]/#src').map {|a| a.value }
to:
puts product.xpath('.//img[#width = 220]/#src').map {|a| a.value }
The point of the '.' there is to say you want all images that are children of the current node (e.g. so you're not peeking at product 2's images).
File#basename will return only the filename:
File.basename('http://www.test.com/product4.jpg')
#=> "product4.jpg"
So you probably want something like this:
puts product.xpath('//img[#width = 220]/#src').map {|a| File.basename(a.value) }

Resources