I'm using Laravel 5 and Bootstrap 3.3.4
So I have the following code in my controller:
$articles = Newsarticles::paginate(10);
return view ('news',compact('articles');
Then in my view I have:
#foreach($articles as $article)
<article>
<h2>
{!! $article->headline !!}
</h2>
<div class="body">
{!! substr($article->article,0,500) !!}
</div>
</article>
#endforeach
{!! $articles->render() !!}
When I run this, the pagination links at the bottom of the page come out just fine and look as they should do. However, if I change the controller to :
$articles = Newsarticles::orderBy('artdate','DESC')->paginate(10);
my pagination links come out like this:
«
1
2
3
4
5
6
»
How can one small adjustment in the code break the css?
Hadn't escaped tags and an open HTML tag was killing off the css. Thanks to #minioz for pointing it out
From my comment above.
The problem was the broken html tag. It is because of using substr() at this line.
{!! substr($article->article,0,500) !!}
The function will cut out part of the $article->article and left some tags open.
To solve to problem you need to remove tags before do substr()
{!! substr(strip_tags($article->article),0,500) !!}
With substr($article->article,0,500) you may breack html code.
You can also have a distinct number of vivible chars
p>hello</p>
12 chars
<stong>hello</strong>
21 chars.
And take care of this:
echo substring('<p>hello</p>', 5);
Writes: "he". Breack html result.
Try with
substr(strip_tags($article->article,0,500))
to strip all html tabs before cut the string. This will not breack your current html and you will get the correct chars length.
Not enough information to answer -- but the three big possibilities are
Somehow you're rendering different HTML in each example
Other CSS you have on the page isn't bullet-proof, and it's creating different container wraps based on headline and content length
There's HTML content in $article->article, $article->slug, or $article->headline with unclosed tags that's breaking the layout (or unexpected tags/styles/classes that interfere with the page CSS)
Make a copy of the raw page source (View -> Developer -> View Source in Chrome) of the page for the different requests and then run through through a diff program (CLI diff, WinMerge, opendiff, etc.) to spot any rendering differences.
Assuming there's none, investigate each but of content area for broken tags, and then start populating your layout with different length headlines and text body area until you trigger the issue, and then fix your CSS from there.
Good luck!
Related
I am trying to display data of CK editor 5 in frontend like this
enter image description here
The image you provided looks like unparsed markdown. In order to convert this into the correct HTML, you'll need to run it through a markdown parser first. In Laravel, you can actually use the built-in parser Laravel uses for emails. In your view, simply wrap the output with Illuminate\Mail\Markdown::parse(). For example, if you are currently using {{ $post->content }}, then you can replace it with:
{!! Illuminate\Mail\Markdown::parse($post->content) !!}
The {!! is to prevent blade from escaping the resulting HTML.
Currently i am doing a CMS in laravel currently i am trying to get all the html removed from posts.
{!! str_limit($post->content, 230) !!}
The problem i am getting is that it gets html as well.
Next i tried Strip_tags function, it didn't display the html.
{!! strip_tags(str_limit($post->content, 230)) !!}
But it didn't displayed anything either..it worked but it counted the html tags as well. I need to just ignore html tags.
Is there any way or function to ignore all the html tags inside the post content and just get the text out of post content?
Thanks
Any help will be appreciated!
Simple use strip_tags with substr
<?php echo substr(strip_tags($post->content,0,110)) . "..."; ?>
I'm making a theme for Bolt (CMS) and it uses the Twig engine.
The website contains articles so I get an article's field like this {{ article.body }}
Now what I wanted to achieve was get the first letter of the body of the article and make it big and then display the rest of the article's body (without this first character) normally, you sometimes see this in books. I managed to do that and I successfully change the style of the first character.
However, using most functions that Twig offers in the documentation, I most often get a "<" as the first symbol as when typing the body of the article in the administration panel it automatically puts a <p> tag to the start.
Is there a way to overcome this?! I wouldn't want my client to have to delete the <p> tag every time. I thought there would be an easy way to get the body without any html in it or something else suitable for my use case.
The way it currently works beautifully:
<span class="firstcharacter">{{ article.body[:1] }}</span> {{ article.body[1:] }}</p>
but this relies on the article not starting with any html
There is a css pseudo-selector for first letter:
.firstcharacter::first-letter{font-size: 50px;}
Would this work for you?
You can use the striptags filter. As example:
{{ article.body| striptags [:1] }}
Here a working example
Hope this help
You shouldn't need to extract the first letter if you use CSS e.g.
Template:
<div class="dropcap">{{ article.body }}</div>
CSS:
div.dropcap p:first-of-type::first-letter {color: #f00;}
That will alter the first letter of the first paragraph.
<div style="margin-top:-21px">
#include('partials.header')
</div>
<div style="margin-top:-21px">
#include('partials.navig')
</div>
<div style="margin-top:0px">
#include('partials.footer')
</div>
Above HTML/Laravel code inserts partials into layout. Every time when I use partial, it will insert empty spaces into HTML output and causing ugly white-space (empty row) above the partial. That's why I am using margin:top:-21px, to hide empty row . But the problem is, that in Internet Explorer are not those white-spaces visible and therefore partials are shifted too much. Here is an HTML output and how empty row looks like:
I have no clue what can cause these white-spaces, it is not wrong margin of elements or something like that. Is there any solution or explanation for this?
I found solution:
Problem was in encoding. Change from UTF-8 to UTF-8 w/o DOM made it.
Alternate solution is wrap partial into div with line-height:0 and div in partials set back to line-height:1.
This is because you are including partials in new row. Try including them in same row and it should fix your problem.
<div style="margin-top:-21px">#include('partials.header')</div>
Laravel doesn't insert blank lines. You should look at your partial files and make sure there are no blank lines / empty spaces at the beginning and at the end. You should also consider including those partials right after closing div and not in next line.
For example:
<div style="margin-top:-21px">#include('partials.header')</div>
<div style="margin-top:-21px">#include('partials.navig')</div>
<div style="margin-top:0px">#include('partials.footer')</div>
And when you put in those partials only the name of file, you will get the following output:
<div style="margin-top:-21px">header</div>
<div style="margin-top:-21px">navig</div>
<div style="margin-top:0px">footer</div>
As you see - no spaces, no blank lines.
Of course the trick with negative margin is the very wrong solutions, so you should analyze your partials and also change including those files to the method I showed here.
i'm creating a cms in php using zend framework where i choose to save at some part html templates to ease redesigning of the views and all.Now to save those templates(views, sidebars) i had to use Zend_Filter_Input with Zend_Filter_HtmlEntities(array('quotestyle' => ENT_QUOTES)
one of the reasons is security, the second is that i use freeRTE to ouput the template for editing, and that freeRTE is very sensitive to quotes so i had to do something.
Now i'm hustling because when i try to output the template back or worst show it in its layout to the public, it shows raw html with tags ,html_entity_decode and htmlspecialchars_decode could not do a thing.example instead of showing the image it show the following on the page :
<div id="welcome"> <div id="welcome_img"><img src="/images/welcome.jpg" alt="welcome" /></div></div>
any clue? it anyone has experienced this please do share the knowledge on that.thanks for reading.
You can't use htmlentities for filter when you save HTML. It will replace <, > and & plus all the replaceable chars.
Edit:
Remove HTMLEntities filter from saving, because saving HTML as-is would be the whole point of template-editor.
If you want to add some security related features, remove tags from the HTML and every other html tag that you find harmful! (embed?)