javascript - How to append @if and @foreach inside a class using onclick function in jQuery -
i want add if
, foreach
statement inside class whenever user select item dropdown box.
tags should added inside is:
@if($article->tags)
@foreach($article->tags $articletag)
@if($articletag->tag == $(this).text())
$(this).text()
text user clicks on dropdownbox. purpose of these if
, foreach
filter table based on filtername($this.text())
whenever user choose item dropdownbox. how do it?
html content before javascript runs:
<div class="content"> @if($articles) @foreach($articles $article) <div class="row article art-content"> <div class="col-xs-12 col-md-6 hidden-xs hidden-sm"> <a href="{{ url('article/'.$article->category->slug.'/'.$article->slug) }}"> <img src="{{ url('image').'/'.$article->featured_image }}?w=460&h=267&fit=crop" alt="" class="img-responsive"/> </a> </div> <div class="col-xs-12 col-md-6 hidden-md hidden-lg"> <a href="{{ url('article/'.$article->category->slug.'/'.$article->slug) }}"> <?php $image = $article->mobile_image != null ? $article->mobile_image : $article->featured_image; ?> <img src="{{ url('image').'/'.$image }}?h=imageheight" alt="" class="img-responsive"/> </a> </div> <div class="col-xs-12 col-md-6"> <h3 class="article-title"> <a href="{{ url('article/'.$article->category->slug.'/'.$article->slug) }}"> {{ $article->title }} </a> </h3> <span>published on: {{ date('m d, y', strtotime($article->published_on)) }}</span> <div class="spacer20"></div> <a href="{{ url('article/'.$article->category->slug.'/'.$article->slug) }}" class="btn btn-primary">read article <i class="fa fa-chevron-right fa-fw"></i> </a> </div> </div> <hr/> @endforeach <div class="text-center"> {!! $articles->render() !!} </div> @else <div class="row spacer50 text-center"> <div class="col-xs-12 spacer50"> <h4>the key entered not match articles. <br/>please click <a href="{{ url('articles') }}">here</a> see list of available articles.</h4> </div> </div> @endif
html content when javascript executes:
<div class="content"> @if($articles) @foreach($articles $article) @if($article->tags) //added line @foreach($article->tags $articletag) //added line @if($articletag->tag == 'whatever text dropdown clicks') //added line <div class="row article art-content"> <div class="col-xs-12 col-md-6 hidden-xs hidden-sm"> <a href="{{ url('article/'.$article->category->slug.'/'.$article->slug) }}"> <img src="{{ url('image').'/'.$article->featured_image }}?w=460&h=267&fit=crop" alt="" class="img-responsive"/> </a> </div> <div class="col-xs-12 col-md-6 hidden-md hidden-lg"> <a href="{{ url('article/'.$article->category->slug.'/'.$article->slug) }}"> <?php $image = $article->mobile_image != null ? $article->mobile_image : $article->featured_image; ?> <img src="{{ url('image').'/'.$image }}?h=imageheight" alt="" class="img-responsive"/> </a> </div> <div class="col-xs-12 col-md-6"> <h3 class="article-title"> <a href="{{ url('article/'.$article->category->slug.'/'.$article->slug) }}"> {{ $article->title }} </a> </h3> <span>published on: {{ date('m d, y', strtotime($article->published_on)) }}</span> <div class="spacer20"></div> <a href="{{ url('article/'.$article->category->slug.'/'.$article->slug) }}" class="btn btn-primary">read article <i class="fa fa-chevron-right fa-fw"></i> </a> </div> </div> <hr/> @endif @endforeach @endif @endforeach <div class="text-center"> {!! $articles->render() !!} </div> @else <div class="row spacer50 text-center"> <div class="col-xs-12 spacer50"> <h4>the key entered not match articles. <br/>please click <a href="{{ url('articles') }}">here</a> see list of available articles.</h4> </div> </div> @endif
javascript:
$('#tags li').on('click', function(){ $('.content').hide(); if($(this).text() == 'all') $('.content').fadein('slow'); else { //add @foreach , @ifs } });
looks using laravel blade template engine, compiled in server. not changed javascript. , them not used together.
the code wrong
@if($articletag->tag == $(this).text())
so need can not achieved. maybe should change thinking find way.
wiki
Comments
Post a Comment