RenderLink returns "Empty String " in Glass.Mapper - sitecore

I'm trying to show a title of a news as a link
#using Glass.Mapper.Sc.Web.Mvc
#model MVC.com.Models.News
it works:#Model.Title<br/>
it dosen't work : #Html.Glass().RenderLink(x => x.Url,new {#class=""} ,true, Model.Title)
Anchor tag works fine but can not generate a link using RenderLink.
Meanwhile, is there any way I can eliminate #Html.Glass() helper from lines? I added Glass.Mapper.Sc.Web.Mvc to file Web.config but still have to wirte #Html.Glass() at the beginning of each command

You can eliminate #Html.Glass() this way:
#using Glass.Mapper.Sc.Web.Mvc
#RenderLink(Model, x => x.Link, new { #class = "btn" }, true,Model.Title)

i think you can do this which should eliminate #Html.Glass()
#inherits GlassView<News>
after that i think you should be able to do this.
#RenderLink(Model, x=>x.Url,new{#class=""},true)

Related

Regex in JSX file not working, trying to remove the quotation marks "" that return around name

const Json = ({ data }: any) => <pre>{JSON.stringify(data, null, 4)}</pre>;
let profileName = <Json data={account.name.replace(/\"/g, '')}/>
not used to using regex, but I am trying to remove all instances of ""
When I use that regex with a normal hardcoded string of a name it works, why doesn't it work with this one?
what'up?
The JSON.stringify() automatically put quotes!
Remove it!
I hope to help!

Angular2 pipe regex url detection

I would like to have a pipe which is detecting any url in a string and creating a link with it. At the moment I created this, which seems not working:
#Pipe({name:'matchUrl'})
export class MatchUrlPipe implements PipeTransform {
transform(value: string, arg?: any): any {
var exp = /https?:\/\/(www\.)?[-a-zA-Z0-9#:%._\+~#=]{2,256}\.[a-z]{2,4}\b([-a-zA-Z0-9#:%_\+.~#?&//=]*)/g;
return value.replace(exp, "<a href='$1'>$1</a>");
}
}
How can I fix it?
Seems like there are two problems with your implementation:
Your regex has the first capturing group ( $1 ) matching the 'www' part of the url. You want to change the regex like this for it to work (note the extra pair of parethesis at the start and end of the regex):
var exp = /(https?:\/\/(www\.)?[-a-zA-Z0-9#:%._\+~#=]{2,256}\.[a-z]{2,4}\b([-a-zA-Z0-9#:%_\+.~#?&//=]*))/g;
Pipes can't render html normally. You need a trick to do that as mentioned in other questione like this. You need to assign your 'piped value' to the attribute outerHTML of a span for example (the span will not be rendered).
Plunker example

CakePHP 1.3: Way to removed a specific string from a text - PHP Function or Regular Expression

I migrated a News database into a CakePHP news site I am creating. I have a problem with displaying the text from those migrated news because in the text that was imported to DB there were HTML tags that controls the text within them.
Could anyone help me find a way to remove these texts without compromising the layout of those same news?
Basically, I would like to accomplish the following:
Create a ONE-Time Use only function that I can include in my ArticlesController
For example the function name would be function fixtext(){...}
When I call this function from lets say http://mydomain.com/articles/fixtext, all the affected rows in the Article.body column would be scanned and fixed.
The section of text I want to remove is font-size: 12pt; line-height: 115%;, which in within the <span>...</span> tag.
I had something in mind like this, but I am not sure how to implement it
function fixtext(){
$this->autoRender = 'FALSE';
$articles = $this->Article->find(
'all',
array(
'fields' => array(
'Article.body',
'Article.id'
),
'recursive' => -1
)
);
foreach($articles as $article){
// Per Dunhamzzz suggestion
$text = str_replace('font-size: 12pt; line-height: 115%;', '', $article['Article']['body']);
$this->Article->id = $article['Article']['id'];
$this->Article->saveField('Article.body', $text);
}
$this->redirect('/');
}
I am not sure how to approach this, and what is the best way.
Firstly, I would personally create a shell to accomplish this as it is a batch job and (depending on the amount of records involved) you may hit Apache's request timeout limit. Also, it's a good (fun) learning experience and the shell can be extended to perform future maintenance tasks.
Secondly, it is a bad idea to parse HTML using (greedy) regular expressions due to the fact it may be malformed. It is safer to use an HTML parser or using simple string replacements instead but, if it is a small regular string that can be pattern matched safely (ie. your not trying to remove the closing </span> tags), regular expressions can work.
Something like this (untested):
// app/vendors/shells/article.php
<?php
/**
* Maintenance tasks for Articles
*/
class Article extends Shell {
/**
* Clean HTML in articles.
*/
public function cleanHtml(){
// safety kill switch (comment before running)
$this->quit('Backup the `articles` table before running this!');
// this query will time out if you have millions of records
$articles = $this->Article->find('all', array(
'fields' => array(
'Article.name',
'Article.body',
'Article.id'
),
'recursive' => -1,
));
// loop and do stuff
foreach ($articles as $article) {
$this->out('Processing ' . $article['Article']['name'] . ' ... ');
$article['Article']['body'] = $this->_removeInlineStyles($article['Article']['body']);
$this->Article->id = $article['Article']['id'];
$saved = $this->Article->saveField('body', $article['Article']['body']);
$status = ($saved) ? 'done' : 'fail';
$this->out($status);
}
}
/**
* Removes inline CSS styles added by naughty WYSIWYG editors (or pasting from Word!)
*/
protected function _removeInlineStyles($html) {
$html = preg_replace('/ style="[^"']+"/gi', '', $html);
return $html;
}
}
You can use a simple str_replace() to cut that piece of text out.
foreach($articles as $article){
$this->Article->saveField(
'Article.body' => str_replace('font-size: 12pt; line-height: 115%;', '', $article['Article']['body']),
'Article.id' => $article['Article']['id']
);
}
This is pending the text is the same in each case, otherwise you will need something a bit more complicated with regular expressions (or maybe multiple str_replace() calls to remove each bad property).

Why is php_template_preprocess_page function not called in Drupal 6x?

From another forum I found the following example:
"I was looking for a way to pull node data via ajax and came up with the following solution for Drupal 6. After implementing the changes below, if you add ajax=1 in the URL (e.g. mysite.com/node/1?ajax=1), you'll get just the content and no page layout.
in the template.php file for your theme:
function phptemplate_preprocess_page(&$vars) {
if ( isset($_GET['ajax']) && $_GET['ajax'] == 1 ) {
$vars['template_file'] = 'page-ajax';
}
}
then create page-ajax.tpl.php in your theme directory with this content:
<?php print $content; ?>
"
This seems like the logical way to do it and I did this, but the phptemplate_preprocess_page function is never called ... any suggestions?
I figured it out for myself from a Drupal Support Theme Development page:
"Maybe this helps
leahcim.2707 - May 29, 2008 - 05:40
I was trying to get the same thing done and for me this works, but I'm not sure if it is the correct way as I'm still new to Drupal:
in "template.php" I added the following function:
function phptemplate_preprocess_page(&$vars)
{
$css = $vars['css'];
unset($css['all']['module']['modules/system/system.css']);
unset($css['all']['module']['modules/system/defaults.css']);
$vars['styles'] = drupal_get_css($css);
}
I think after adding the function you need to go to /admin/build/themes so that Drupal recognises the function."
The part in bold is what did the trick ... you have to re-save the configuration so it recognizes that you've added a new function to the template.

getElementsByTagName setAttribute and regex javascript

i want to put rel=lightbox to some links that mediabox support using javascript.
i try this and wonder why it's not working?
test: http://jsbin.com/opica
please help edit this: http://jsbin.com/opica/edit
<script type="text/javascript">
var x=xmlDoc.getElementsByTagName("a");
var regexku=/^.+(((twit)|(tweet)|(com/video.+)|(flickr.com.+)|(tube.com.+))|((gif)|(jpe?g)|(png)|(flv)|(swf)|(mp3)|(mp4))$)/;
for(i=0;i<x.length;i++)
{
a=x[i].getAttribute('href');
if (a.match(regexku) != null)
{
x.item(i).setAttribute("rel","lightbox");
}
}
</script>
So if you open the Error Console (Tools -> Error Console in Firefox), you'll see two errors on your page:
Error: xmlDoc is not defined
Source File: http://jsbin.com/opica
Line: 35
Error: invalid regular expression flag v
Source File: http://jsbin.com/opica
Line: 21, Column: 38
Source Code:
var regexku=/^.+(((twit)|(tweet)|(com/video.+)|(flickr.com.+)|(tube.com.+))|((gif)|(jpe?g)|(png)|(flv)|(swf)|(mp3)|(mp4))$)/;
The later is fixed by escaping the slash as Bart suggested (com\/video).
The former says there's no such thing as xmlDoc. You probably meant the page's document, in which case you should replace it with document.
Next the whole thing probably won't work because you should run the script after the page is finished loading. In jQuery it's $(document).ready(function() { /* do your work here */ }), google how to do it using the whatever framework you're using (mootools-yui?).
After that as you can see, the rel attribute is set on the links: http://jsbin.com/elaca/edit. The fact that the whatever library you're using still doesn't work means you're using it wrong. You didn't even link to the page you've downloaded the library from so that someone could look up the documentation for you...
Try escaping the / between com and video.