0

I am trying to grab all links under id="ctl00_ctl00_MainPlaceHolder_MainPlaceHolder_TaobaoLink".

Here is the function used in my custom module file:

function _taobao_add_tovar($url){
  $url = str_replace('&','&',$url);
  $tovar_page = _taobao_get_page('http://rutaobao.com/pages/item_detail.aspx?ItemId='.urldecode($url));

  $linkz = _taobao_get_block($tovar_page, '"ctl00_ctl00_MainPlaceHolder_MainPlaceHolder_TaobaoLink" title="Открыть оригинальную страницу этого товара на taobao.com">');
  preg_match_all('%<a [^>]+href="(?P<url>[^"]+)"[^>*]*>(?P<text>[^< ]+)</a>%si', $tovar_page, $linkz);
}

I've set the $linkz variable. How can I print it in node-mycontenttype.tpl.php?

2

To get a variable to a custom node.tpl.php you need to do this in MODULE_preprocess_node(&$variables) usually this is done in your template.php file located inside your themes directory, however, because you are calling a private function _taobao_get_page(), I think you need it inside your module.

Something like

MODULE_preprocess_node(&$variables) {
   if ($node->type == 'mycontenttype') {
      $variables['linkz'] = X;
   }
}

Now you can call $linkz inside your tpl.php file

  • It throws me an error - Parse error, unexpected '[' – Alexander Kim Jul 9 '11 at 12:21
  • variables['linkz'] = $variables['linkz']. Edited my answer – iStryker Jul 9 '11 at 12:28
  • If you are trying this inside your custom module, then let me know if this works and if the $node variable is available. I know the $node is available in the theme's THEME_preprocess_node() function – iStryker Jul 9 '11 at 12:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.