By sea_drupal on
Dear Drupal guru:
Could I ask what the best way is to implement below case:
1>curently, the content type contains a field of "stock code". its value could be like text "GOOG" ( google company) ;
2> then how the webpage automatically concatenate fixed string "https://sg.finance.yahoo.com/q?s=" with "GOOG" and generate the URL like " https://sg.finance.yahoo.com/q?s=GOOG" for user to click
thank you !
Comments
#Re
curently, the content type contains a field of "stock code".
=> What is the type of field ? Could you please provide details ? And are you doing any pre process before rendering the field ? Are you rendering this field through views ?
the "stock code" is just a name, which is text type field
so far, I am not doing pre process or don't know how to do pre-process, if it is required, could you show me ?
the type of field is just "text".
I just want to fill in this field the text like "GOOG" ( google) or "MSFT" (Microsoft), etc , then the webpage can show the full URL something like "https://sg.finance.yahoo.com/q?s=GOOG" or "https://sg.finance.yahoo.com/q?s=MSFT" automatically, so the viewers can just click the URL and go to the webpage.
I don't want to hard code , e.g key in the whole text field like "https://sg.finance.yahoo.com/q?s=GOOG" or "https://sg.finance.yahoo.com/q?s=MSFT" into any field.
thank you !
wait, how do you want to do
wait, how do you want to do it?
the link will show or redirect to that link after the form was submitted?
it doesn't matter whether the link is showed or redirect
it doesn't matter whether the link is showed or redirect.
the Key points are
1>how to concatenate the string with one or few fields or even hard coded "string" to form a new String
2> how to automatically let the new string become the "URL" and shown to audience
thank you !
then you can make your submit
then you can make your submit function to get that field value and use the function drupal_goto($yourPath, array('query'=>array('s'=>$form_state['sometyhing'])));
after the form is submitted, you will be redirected.
that's not exactly the code but you can get the gist of it
thanks Xandiel. but the methods looks complicated.
I don't want to be "redirected". Just the published webpage shows the "concatenated" string , which is also with URL format.
it doesn't matter whether the
the last thing i can think of to do this is js or drupal set message lol
You don't say whether you're
You don't say whether you're on D7 or D8...
I'd handle this one of two ways:
- theme template: you can create a theme template specifically for that field (you should read up on template naming conventions and suggestions), and add your code into the template, wrapping the content of the field.
So in D8/Twig this might be https://sg.finance.yahoo.com/q?s={{ output }}
The {{ output }} part is twig markup representing the content of the field as it would be displayed if you did nothing.
In D7/PhpTemplate your code would be different, but the concept is the same
- Display Suite - if you'd prefer to do this from the Admin interface, DS can rewrite your fields for you. Be sure to turn on Display Suite Extras so you get the field formatting on your Manage Display tab. Display Suite also has a bit of a learning curve, but once you get it, its unusually handy.
============================
Resonetrics: Better Tools for Building Brands
http://resonetrics.com
http://technologyformarketers.com
http://kittenassociates.org
http://www.linkedin.com/in/sammooreatresonetrics
Display suite is useful
Thanks Sam Moore a lot , the Display suite is quite useful. I am using Drupal 7.
1 > I can “add custom code” like below and works
2> But I got problem when add a field of my content,
The error is
“
Notice: Array to string conversion in eval() (line 8 /public_html/sites/all/modules/ds/modules/ds_format/ds_format.module(66) : eval()'d code).
“
Could someone advise ?
Thank you !
just found the error
print "$entity->field_stockcodetest['und'][0]['safe_value']";
change to
print $entity->field_stockcodetest['und'][0]['safe_value'];
or
$test=$entity->field_stockcodetest['und'][0]['safe_value'];
print $test
Can Display suite "customer code" include Javascript ?
Can Display suite "customer code" include Javascript to handle data like Json