I need to build and print a deeplink to any given comment. So that the user can directly access the specific comment with just clicking a link. I could not find a native drupal function to get this so i build it my own.
My solution
<?php
global $base_url;
$base = drupal_lookup_path('alias',"node/".$node->nid);
$path = $base_url.'/'.$base.'#comment-'.$comment->cid;
$link_options = array('html'=> $html);
$commentlink = l($date, $path, $link_options);
?>
To print the link you only have to call <?php print $commentlink;?>. But i'm pretty sure there is better and much more drupal like way to solve the problem.
The Better Way
Mikeker did it :) As he suggested here are the solution.
<?php
$commentlink = l(
$date,
"node/$comment->nid",
array("fragment" => "comment-$comment->cid"));
?>
Note the little difference bettween Mikeker and my version. array("fragment" => "comment-$comment->cid")); and array("query" => "comment-$comment->cid"));
The query param will add an ? to the url. So your path looks like
//…query
http://example.com/path/to/node?comment-2
In opposite to my solution (fragment):
//…fragment
http://example.com/path/to/node#comment-2
Note:
Do not include the leading '#' character to a fragment identifier. It will be added by drupal.
That's basically the way to do it. Comment permalinks are in the form of:
node/<nid>#comment-<cid>
Where <nid> and <cid> are the node and comment IDs, respectively. You can save yourself a step by not doing calling drupal_lookup_path() -- l() or url() do it for you. The shortened routine would look like:
$commentlink = l(
$date, // Text of the link
"node/$node->nid", // path to node, l() handles aliases
array('query' => "comment/$comment->cid"), // fragment to specific comment
);
In case anyone was wondering, the Drupal 7 way (at least, appears to be) this:
<a href='http://YOURSITE.com/comment/CID#comment-CID'>link text</a>
For example:
print "<a href='/comment/$comment->cid#comment-$comment->cid'>text here</a>";
And this would be placed in, perhaps, a comment.tpl.php file.
Related
I am trying to change the title of a page.
The default.ctp view has the following code:
<title>
<?php echo $this->fetch('title'); ?>
- Welcome
</title>
I'm trying to use the following code in the controller of the page:
$title = 'Overview';
$this->set('title');
But unfortunately I do not see see 'Overview - Welcome', but only the name of the function of the controller followed by ' - Welcome'.
Can anyone help me to find the problem why it is not working?
Don't know if $this->set('title') will work
I usually use the 'compact' function to set the variables as they're named.
Like this: $this->set(compact('title')); or just simply this $this->set('title', $title);
You can define what $this->fetch('title') returns using View::assign() function that sets block's value this way:
$this->assign('title', $title);
See more in the documentation about view blocks.
I think instead of:
$this->set('title');
you must use:
$this->set('title', $title);
I'm trying to change headtitle on ZF2 but it always say "ZF2 Skeleton Application" when i paste it on FB
How can I change it?
I tried few things and cant make it work
I event tried raw HTML inside head tag to put it and it doesn't work, BUT on my other pages this works but don't know why
echo $this->headTitle('you are on '.$news.' ');
inside PHP ofc
If you want to set head title, Do not use 'echo' in front, just use:
$this->headTitle('you are on ...');
...in your view php file.
If you want to change the head title from inside a controller method use:
$this->getServiceLocator()->get('ViewHelperManager')->get('HeadTitle')->set('my title')
To my understanding you want to change the head title of the main (front page).
You can put the following in your layout.phtml page.
<?php echo $this->headTitle('you are on'. $this->translate($news))->setSeparator(' - ')->setAutoEscape(false); ?>
I try to write a link from a first page that will open a second page that includes prettyphoto and automaticaly open the prettyphoto plugin including a third page. Doing that, I've got to transmit a variable from the first link and retrieve it in the third.
Is it possible ?
Yes, it is: If the first an the third website were running on the same server you wil be able to use HTML5 Web Storage or Cookies. Here's an example (HTML5 Webstorage):
// Save...
localStorage.setItem('item', myVariable);
// Open...
var myVariable = localStorage.getItem('item');
I have found the following issue
I added a variable into the link of the first page
mypage.php?my_variable=<? echo $id; ?>
and on the second page, test the presence of this variable to implante an automatic launch of prettyphoto into the jQuery function init :
<?PHP
if(isset($_GET['my_variable'])) {
$id = $_GET['my_variable'];
?>
$.prettyPhoto.open('third_page.php?id=<?PHP echo $id; ?>&ie=UTF-8&oe=UTF-8& q=prettyphoto&iframe=true&width=100%&height=100%');
<?PHP
}
?>
I'm now looking for a full screen prettyphoto auto opening, but that's another problem, the main problem is solved for me.
I have a php file under protected/views/directory_controller_name with formatting like that
<p>
<?php echo $model->title;?>
</p>
...
I display the file with classic method in the controller :
$this->render('filename',array('model'=>$model));
But know, I need to send an email with the same template/layout so I want to store the render of the file in an variable like
$msgHTML = $this->renderInternal('_items', array('model'=>$model));
But it doesn't work!
How can I get render view from a file and store in a variable?
Is it possible?
I don't want to use:
$msgHTML = '<p>'.$model->title.'</p>'
...
Because the file is very long and I don't want to duplicate code!!!
Don't use the renderInternal method, use renderPartial instead. Render internal is low level method and should not be used in such context. To catch the output just set the $return parameter to true:
<?php $output = $this->renderPartial('_subView', $dataArray, true); ?>
$msgHTML = $this->renderInternal('_items', array('model'=>$model), true);
http://www.yiiframework.com/doc/api/1.1/CBaseController#renderInternal-detail
I might be missing something, but can't you just use regular render() with the return argument set to true? Then you can just use a view 'name' instead of knowing the path. (And unless my trusty stack trace logger is broken, renderFile and renderInternal take the same fully qualified path argument. At least I can see renderPartial() passing the full path to my view file to renderFile.)
you can do this with these ways
1) if you want to get the output with header and footer (i.e ) full layout then do this
//add true in the last parameter if you want a return of the output
$htmloutput=$this->render('_pdfoutput',array('data'=>'nothing'),true);
2) similarly if you don't want to get the layout files just use renderpartial in the same way
$htmloutput=$this->renderpartial('_pdfoutput',array('data'=>'nothing'),true);
you will get the html of files in the variable . use this anywhere
jQuery UI starting from version 1.8.4 html-encodes Autocomplete suggestions (according to this issue).
This became a problem for me now. I used to theme the output for the suggestions, but now (if I use version 1.8.4 or higher) Autocomplete just html-encodes my theming. All tags like <b>, <span> are being printed to the user instead of displaying the actual styling.
So the suggestions now look like:
<b>su<b>suggestion
another <b>su<b>suggestion
instead of:
suggestion
another suggesion
I've read about custom data, but I use Yii framework and the output is being generated from certain actions (PHP code).
So, how do I theme the output now?
Thank you!
Better use a HTML plugin
You can use open function from jQuery UI to replace the encoded text.
Here's an example:
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'name'=>"bug",
'source'=>$this->createUrl('/autocomplete'),
// additional javascript options for the autocomplete plugin
'options'=>array(
'open'=> 'js:function(event, ui){
$("ul.ui-autocomplete li a").each(function(){
var htmlString = $(this).html().replace(/</g, "<");
htmlString = htmlString.replace(/>/g, ">");
$(this).html(htmlString);
});
}'
),
));