I seem to be having a problem with haml. Rails is rendering:
%span
stuff
#div_name
moar stuff
as
<span>stuff</span>
<div id='div_name'></div>
moar stuff
any ideas? why isn't 'moar stuff' inside the span?
Works fine for me:
$ echo '%span\n stuff\n #div_name\n moar stuff' | haml
<span>
stuff
<div id='div_name'></div>
moar stuff
</span>
Try this:
%span
stuff
#div_name
moar stuff
The span only contains stuff, so you have to undent after stuff, so that other elements are not contained in the span.
You can also write it like this:
%span stuff
#div_name
moar stuff
Which gives exactly this:
<span>stuff</span>
<div id='div_name'></div>
moar stuff
Related
I am having trouble writing simple logic using blade when attributes are involved for instance
<a href='#' class= {!!$activeCategory==$category->id ?
'accordion-toggle active ' :
'accordion-toggle inactive '
!!} />
i want it such that i can switch between the two last classes for my tag. also the first item remains unchanged i cannot concatenate as i cant use braces midway an attribute, however still when using it like this for some reason only the first word is set in the class string and the last is broken out of the string into just a hanging attribute. i hate that . how can i solve this and still write it in an concise manner or what's the trick in working with those curly braces in laravel, there always seems to be a catch each and every other time unlike how it works in other templating engines. the following is the created code on element inspect
<a href='#' class="accordion-toggle" active />
3 things:
You don't need {!! !!} for non-html {{ }} is fine
Don't repeat "accordion-toggle"; put it outside the braces
Wrap everything in " ", use ' ' in the braces:
<a href="#" class="accordion-toggle {{ $activeCategory == $category->id ? 'active' : 'inactive' }}"> ...
I have a $brick which is an instance of Crawler and this is how $brick->html() starts:
<div>
<div>testplain 1</div>
</div>
I am fishing out the div containing testplain 1 with:
$content = $brick
->children()->first()
->children()->first();
but this is not nice. I know I could drop first() but that would make it even more confusing IMO. Is there a way to say first <div> of the first <div> in a nicer way with DOMCrawler?
I want to declare a scala variable in a view file. How can it be done?
#(title: String)(content: Html)
//this line isnt compiling. I tried without the word defining but it doesn't work either
#defining(l:Seq[String] = Seq("hello","hello2"))
<html><head>...
<body>
#content
//I want to use the list here
<ul id="hardcode-list" >
#l.map{item=><li>item</li>}
</ul>
</body>
</head></html>
for completeness sake, I solved my issues by this code
<ul id="hardcode-list" >
#defining(List("hello","hello2")){l=>
#l.map{item=>
<li>#item</li>
}
}
Is there any way to generate many divs nested each other?
I expect print some like this:
<div>
<div>
<div>
<div>
<div>
</div>
</div>
</div>
</div>
</div>
Simple loop is not helping
- (1..5).each do |i|
%div
Goes to
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
There isn't any way of doing this in pure haml, by design.
Firstly, ask yourself: Do you really need this? There are often far better ways to achieve the result you want.
In my case, I needed an arbitrary nesting of divs with a particular class, based on a number I was given externally. I added the following to my rails helpers:
def nestify(css_class, level, &block)
if level > 0
content_tag(:div, class: css_class) { nestify(css_class, level - 1, &block) }
else
yield
""
end
end
Then, in your haml, you use it with a block:
= nestify('each-div-has-this-class', 5) do
Content for inner div.
[Edit] Quick note: I wrote this a while back, can't remember why - but this code is not production ready. Ruby doesn't work well with recursive functions. Please flatten it into a loop for better performance / scalability.
I am using orbit for slideshow requirements, however I am not able to add captions.
The documentation says this :-
<div id="featured">
<img src="overflow.jpg" alt="Overflow: Hidden No More" />
<img src="captions.jpg" alt="HTML Captions" data-caption="#htmlCaption" />
<img src="features.jpg" alt="and more features" />
</div>
<!-- Captions for Orbit -->
<span class="orbit-caption" id="htmlCaption">I'm A Badass Caption</span>
I am using haml and doing something like this :-
.container
.row
.two.columns
=render "left_navigation"
.ten.columns.destination_tabs
.contianer
.row
.ten.columns
%h3 Featured Destination
%hr
-if #preferred.blank?
%h5 No Featured destinations currently
-else
#featured
-#preferred.each do |destination|
-destination.destination_photos.each do |photo|
=image_tag(photo.picture.thumb_large.url, :alt =>"html captions", :data-caption => "#htmlCaption")
.orbit-caption#htmlCaption
="sfsdf"
This obviously gives error because I cannot give a syntax like :data-caption I tried lot of stuff but couldn't get it right yet can anyone help?
You can use arbitrary strings as symbols by simply quoting them:
:"data-caption" => "#htmlCaption" #note the quotes around data-caption