Laravel Blade Php View: Is there a way to ignore any space before "#foreach #if" . etc? - laravel

I am new to Laravel.
It seems like in default setting, the following code
#foreach($foo as $bar)
<div>
would generate 8 white spaces before the div in actual final html code.
I want to know is there a way to ignore the 4 spaces before the #foreach and only use the 4 spaces before the div?
A related but different question: Laravel Blade comment before "#if"
In this question the author seems to do what I am doing right now, which is essentially leave no space before the #foreach but the drawback is the source code looks ugly. Ideally there should be a way to make the code look nice while also not affecting the final output.

Related

Line breaks not working properly with Laravel Text Emails / Testing in Mailhog

If I understood correctly, in laravel text emails it is not necessary to add "\n" for example,
but it seems that, some times the "enters" ( new lines ) I add work properly, sometimes not.
I've been trying to figure it out anc it is a mystery, seen some people with the same issue but haven't found a solution yet.
Some examples/tests below:
Edit:
HTML is not being used! I'm calling ->text( and not->view(:
Added 2 spaces BEFORE the line break, Issue solved.
Make sure your IDE is not trimming spaces at the end!!
Which was my case with VSCode ( not sure if some plugin or native will figure out soon )
You are using Blade Template from Laravel, and Blade uses html tags.
In your case, since you are using HTML anyway, why not use breaklines, paragraphs, divs or anything that is a block element so that you can efficiently add a newline.
<p>
<br>
<div>
Or much better approach is to use Markdown template for Emails as documented from official Laravel page, Markdown mailables

Laravel string limit with html tag shows less item than the actual number of items

I am using laravel and blade to loop over some blog items. I wanted to show blog with html tags and also with str_limit function.
When I try
{!!str_limit($blog->body, 450)!!}
It only shows 10 blogs or 11 out of 22. It should show all items.
If I use {{ str_limit($blog->body, 450) }} it shows all but without html tags I mean no effect of html tag.
str_limit has no knowledge of HTML tags, so using it on a string that contains HTML will often result in an unclosed tag that breaks the rest of the page.
As an example, an excerpt that ends in <a href="http://google.co because it got lopped off there means the rest of your page is part of the <a> tag until you accidentally output a " and a > again.
A couple options are available to you:
Strip the HTML tags. I know you wanted to preserve them, but this remains the easiest way of generating an excerpt.
Output the entire body, but give it max height and an overflow: hidden to hide the rest. This has bandwidth downsides, so if your posts are enormously long, it may not be the best approach.
Produce your own excerpts as a separate field. Manual work, but you're always in control that way.
Find/code a HTML-aware excerpt generator. I'm not aware of a good one I can recommend - it's a complicated problem. You could try generating a str_limited string and then running the results through Tidy, which can sort of fix invalid HTML.

How can I stop Joomla from stripping HTML code from the Contact info?

I've only spent maybe 30 mins searching online for this, and couldn't come up with a decent answer.
But anyway, in Joomla there are normal input fields for the Contacts component, but there's a textarea for the Address.
This would make me assume you can enter multiple lines of address in there, and it would be displayed as separate lines... but it doesn't. Even if I enter line breaks, the output is rendered on one line.
So I try to enter <br> to separate, and upon saving, Joomla strips these tags out.
In the template, the output is being written simply by echoing $this->contact->address
Is there anyway, to explode this input and replace linebreaks with <br> marks?
UPDATE:
For now as a temporary measure I'm able to add HTML code into the database values, which saves and outputs on the front end.
On a separate note, I'm now looking to remove the Subject line from the contact form, without hacking the code. and by using overrides as much as possible. Can anyone help?
Have you tried the Sourcerer extension?
Your question is pretty old, but did you get a solution to this Lee?
To create line-breaks in Joomla, titles, text areas etc. Easiest way to do this is to use the ReReplace extension from NoNumber: http://extensions.joomla.org/extensions/edition/replace/4336
I personally use this to add line break in e.x. menu-item titles, where < br / > aren't allowed and get stripped.
With ReReplacer, you can create a custom tag e.x. {br} and then have ReReplacer replace {br} with < br / >.
So everytime you need to add a line break anywhere in Joomla, where html codes usually get stripped, you can just add {br} to have it add a new line.
Very old question but I've fallen into the same issue and tried to find a more user friendly solution.
You can enter multiple lines in the address textarea, and they are correctly outputted to the HTML page source. But as you know, newlines in HTML are not rendered, they have to be transformed to <br>.
For this PHP has a nice function, nl2br, that inserts a <br> each time it encounters a newline in a string.
So in html\com_contact\contact\default_address.php of your template, replace:
echo $this->contact->address;
with
echo nl2br($this->contact->address);
This would nicely do the job, and allow the user to naturally insert any newline in the contact address textarea that will be correctly rendered with the appropriate <br>; I believe this is quite more user friendly solution than your previous one of the user having to insert -br- tags in the address field.

CKEditor with HTML content stores, displays but cannot display for edit

I have used CKEditor for a few years without really understanding it. I now want to use it to display text which will include HTML, CSS, JavaScript and PHP example code. None of that needs to execute it is just to show the code to others.
Currently I used the textarea replace method to edit content and I need to carry on that way. When I add the content first time it is sanitised (mysqli_real_escape_string) and stored in a MySQL database correctly. It also then displays correctly with the CKEditor markup working as markup and the HTML/PHP showing as a code example. However, when I edit the content a second time the HTML examples become "real" HTML and are no longer visible as examples.
For example this:
<?php echo "hello"; ?>
<p>Hello</p>
is correctly (?) stored as:
<p><?php echo "me"; ?></p>
<p><p>Hello</p></p>
and displays on the page as shown in the first code snippet (which is what I want). When I then hit edit again the code examples vanish into the background as real HTML (part of the page). If I put the code examples in as code snippets (which I would rather not have to do because of the intended users) the result in the editor (second edit) looks like this:
<!--?php echo "me"; ?-->
Hello
I am sure i am missing a basic understanding of what is going on behind the scenes but can anyone explain how to allow users to type in text which includes HTML, CSS, JavaScript, PHP and MySQL code examples which must then appear as examples and not markup (and be editable as examples).
I have played with config.entities and config.protectedSource after some research but they do not seem to be relevant (or to work). Weirdly a couple of times it seemed to work fine and I thought I had cracked it but then stopped with no further changes to the config. That means I now have less idea what I am doing than when I started!
You don't mention which version you are using, but if it's relatively new (4.4+) you can use the Code Snippets plugin that was designed exactly for this. See the demo at http://ckeditor.com/demo#widgets. It might help with the encoding issues too. There's docs on it too.
Th help with the current encoding issue, it would help a LOT if you showed us how you output the data and load it into CKEditor. For example "When I then hit edit again" doesn't really describe anything without context. For example, do you use setData() with AJAX? Do you use an inline editor? Code examples would be the best.

mvc 3 partials and usage

We meet again stackpeople!
I have been using the last 2 days trying to find the answer I need.I can't seem to find a straight forward answer on WHEN to use partialviews I know you can use em for like login component and all the other fancy stuff
.
But what about the navigation bar ? I tried making the navigationbar with partials and Ajax.htmlactionlink but then the problem comes, I know since its just a partial my URL won't get rewritten which means on f5 it will always update my home/index since no URL was given . Is this cus I can't make my navi like that or just because im plain stupid ?:)
Partials should be used to avoid code duplication. Create one if you find yourself writing the same view code over and over again.
A navigation bar sounds more like something that should be in the layout. You can use Sections in Razor and ContentPlaceHolder for the webforms view engine if you want to let pages customize the layout.
I don't think the partials have anything to do with it(it shouldn't, partials are just a way to split up source files so you can reuse them later).
I'm guessing the problem lies in the use of AjaxhtmlActionlinks, why would you want to do an Ajax call to redirect the user?
Try using the normal #Html.ActionLink()

Resources