In my component, I am trying to pass a dynamic string prop to the image src
<template>
<div class="flex flex-column col-12 md:col-6 xl:col-4 surface-card p-4 border-round border-bg text-left">
<h2>{{ title }}</h2>
<a :href="url">
<img :src="require(`../assets/images/${image}.png`)" class="portfolio-img" alt="" />
</a>
<div class="font-medium text-500 mb-3">
<p>{{ text }}</p>
</div>
<a class="p-button p-component p-button-raised p-ripple external-link" :href="url" target="_blank">Visit</a>
</div>
</template>
And in my View I am trying to create a for loop to display all of the properties. The data is coming from a very simple json file.
<Card v-for="item in portfolioData.portfolio"
:title="item.title"
:image="item.img"
:url="item.url"
:text="item.text">
</Card>
{
"portfolio":
[
{
"title": "test",
"url": "test",
"img": "AICN-Group",
"text": "test test test"
}
]
}
I get issues with Webpack when trying to do this
error: Cannot find module './undefined.png'
at webpackContextResolve (eval at ./src/assets/images sync recursive ^\.\/.*\.png$
I don't understand this at all so could do with some help understanding it as well as a solution if possible. I've tried other solutions on SO but they don't seem to work.
Thanks.
Related
Goal : Only change the parent node to BLUE color and not the nested parent node(which is yellow)
We are trying to change the color of the just parent node in the mat tree and not the nested parent node. If the change the color of the parent node, it is also affecting the nested parent tree node.
Is there to identify only the top node not the nested top parent tree to affected the folder color like shown in the below diagram.
<mat-tree [dataSource]="nestedDataSource" [treeControl]="nestedTreeControl" class="protocol-tree">
<mat-tree-node *matTreeNodeDef="let node" matTreeNodeToggle>
<li class="mat-tree-node">
<div class="type-icon">
<span *ngIf="node.location === null; else file" class="folder-color">
<img src="./../../../../../assets/icons/MaterialIconFolder.svg">
</span>
<ng-template #file>
<img src="./../../../../../assets/icons/MaterialIconDraft.svg">
</ng-template>
</div>
<span class="file-text">
<div *ngIf="node.location === null; else fileText">
{{ capitalizeFirstLetter(node.name) }}
</div>
<ng-template #fileText>
<a (click)="downloadProtocolDocuments(node)">{{ node.name }}</a>
</ng-template>
</span>
</li>
</mat-tree-node>
<mat-nested-tree-node *matTreeNodeDef="let node; when: hasNestedChild">
<li>
<div class="mat-tree-node">
<div class="type-icon">
<span *ngIf="node.location === null; else file" class="folder-color">
<img src="./../../../../../assets/icons/MaterialIconFolder.svg">
</span>
<ng-template #file>
<img src="./../../../../../assets/icons/MaterialIconDraft.svg">
</ng-template>
</div>
<span class="file-text">
{{ capitalizeFirstLetter(node.name) }}
</span>
<button mat-icon-button matTreeNodeToggle [attr.aria-label]="'toggle ' + node.name">
<mat-icon class="mat-icon-rtl-mirror">
{{
nestedTreeControl.isExpanded(node)
? "expand_less"
: "expand_more"
}}
</mat-icon>
</button>
</div>
<ul [class.protocol-tree-invisible]="!nestedTreeControl.isExpanded(node)">
<ng-container matTreeNodeOutlet></ng-container>
</ul>
</li>
</mat-nested-tree-node>
</mat-tree>
</div>
Help is appreciated !
I think i was able get it resolved using level property
<mat-nested-tree-node *matTreeNodeDef="let node; let l=level; when: hasChild">
https://angular-2tsce2-l7qhtt.stackblitz.io
In res.data.tweets i am fetching tweets from server and storing values for every tweet in tweetData obj. In tweet_text, i would like to add a link to the tagged twitter users(clickin on tag will redirect to twitter profile). I figured out how do i find tagged users but i am not able to add a link either with .link or .href attribbute.
axios.post(API_URL, null, { params }).then(res => {
this.currentPage = res.data.page
this.numberOfPages = res.data.numberOfPages
res.data.tweets.forEach(tweet => {
const tweetData = {
id: tweet.id,
tweet_text: tweet.tweet_text,
twitter_name: tweet.twitter_name,
twitter_username: tweet.twitter_username,
added_at: moment(String(tweet.added_at)).format('MM/DD/YYYY hh:mm'),
}
this.tweets.push(tweetData)
// Below this line i am trying to achieve something by adding a link
this.tweets.forEach(el => {
el.tweet_text.split(' ').forEach(word => {
if (word.includes('#')) {
// word = 'this is tag'
word.link('https://twitter.com')
console.log(word.link)
}
})
})
})
})
This is component where data is shown
<div class="tweets-container">
<div
v-for="tweet in tweets"
:key="tweet.id"
>
<div class="tweet-card">
<div class="username-time">
<div class="user-info">
<p class="name">
{{ tweet.twitter_name }}
</p>
<p class="user-info-p">
#
</p>
<p class="username">
<a
:href="'https://twitter.com/' + tweet.twitter_username"
class="twitter_link"
target="_blank"
>
{{ tweet.twitter_username }}
</a>
</p>
</div>
<div class="time">
<p>{{ tweet.added_at }}</p>
</div>
</div>
<div class="text">
<p>{{ tweet.tweet_text }}</p>
</div>
</div>
</div>
</div>
I don't think it's going to work this way.
You should use a computed property which will append the username to the twitter base link. Then, in your template, you can link the href property to the computed property.
computed: {
userLink: function () {
return "http://twitter.com/" + this.tweet.twitter_username
}
}
You can now use this "userLink" directly in your template.
<p class="username">
<a
:href="userLink"
class="twitter_link"
target="_blank"
>
{{ tweet.twitter_username }}
</a>
</p>
I didn't test the code I wrote, feel free to let me know if you need further advice ;)
.Handlebars file
{{#each products}}
<div class="col-xs-6 col-sm-4 col-md-4 col-lg-4">
<div class="product_block">
<div class="product-image-container image">
<a href="#" class="product_img_link">
<img src="{{**???**= /images/product-1-1.jpg}}" alt="product-1-1" class="img-product" />
<span class="product-additional">
<img src="{{**???**= /images/product-1-2.jpg}}" alt="product-1-2-back" />
</span>
</a>
.index.js
app.get('/collections/all', (req, res) => { res.render('collections/all', {
title: 'All Products',
products: [
'/images/product-1-1.jpg',
'/images/product-1-2.jpg',
'/images/product-2-1.jpg',
'/images/product-2-2.jpg'
] }); });
Q. As you can see, I want to apply like 'product-1-1' and 'product-1-2' each <img>
But How can I apply each <img> as {#each} ???
Because I have to repeat <div class="col->..
So it is hard to apply ?
Excuse me, please help me ~
I think you have to rearange your data. At least you will have the opportunities of the (dynamic) each loop instead of comparing (static) filenames.
products: [
{
front: '/images/product-1-1.jpg',
back: '/images/product-1-2.jpg',
altFront: 'product-1-1',
altBack: 'product-1-1-back'
},
{
front: '/images/product-2-1.jpg',
back: '/images/product-2-2.jpg',
alt: 'product-2-1',
altBack: 'product-2-1-back'
},
]
{{#products}}
<div class="col-xs-6 col-sm-4 col-md-4 col-lg-4">
<div class="product_block">
<div class="product-image-container image">
<a href="#" class="product_img_link">
<img src="{{front}}" alt="{{altFront}}" class="img-product" />
<span class="product-additional">
<img src="{{back}}" alt="{{altBack}}" class="img-product" />
</span>
</a>
</div>
</div>
</div>
{{/products}}
I want to use an image on my ejs code, but I use loop with JSON array, so I want to make image url to object of JSON.
I put the JSON object way on the source code.
{
"champion" :
[
{
"id": "266",
"key": "Aatrox",
"name": "Aatrox",
"origin": ["Demon"],
"class": ["Blademaster"],
"cost": 3,
"img" : "https://ddragon.leagueoflegends.com/cdn/9.17.1/img/champion/Aatrox.png",
This json file's local data name is "cdata".
<!-- Champion Data -->
<% for(var i=0; i<cdata.champion.length; i++){ %>
<div class="col-xl-12 col-md-6 mb-12">
<div class="card border-left-primary shadow h-100 py-2">
<div class="card-body">
<div class="row no-gutters align-items-center">
<div class="col mr-2">
<div class="text-xs font-weight-bold text-primary text-uppercase mb-3"><h3><%= cdata.champion[i].name %></h3></div>
<img src= <%= "cdata.champion[0].img" %> class="ChampionImage__ChampImage-xj39xo-2 fhAQxz">
<div class="h5 mb-0 font-weight-bold text-gray-800"><%= cdata.champion[i].key %></div>
</div>
<div class="col-auto">
<i class="fas fa-calendar fa-2x text-gray-300"></i>
</div>
</div>
</div>
</div>
</div>
<% } %>
My website shows broken image https://ykyuen.files.wordpress.com/2015/10/svg-image-broken.png
after that, I changed the code to
<img src= "<%= cdata.champion[0].img %>" class="ChampionImage__ChampImage-xj39xo-2 fhAQxz">
and
<img src= <%= cdata.champion[0].img %> class="ChampionImage__ChampImage-xj39xo-2 fhAQxz">
but it still doesn't work.
You can simplify your code from using for loop to use .forEach Here is docs
<% cdata.champion.forEach(function(champion){ %>
<div class="col-xl-12 col-md-6 mb-12">
<div class="card border-left-primary shadow h-100 py-2">
<div class="card-body">
<div class="row no-gutters align-items-center">
<div class="col mr-2">
<div class="text-xs font-weight-bold text-primary text-uppercase mb-3"><h3><%= champion.name %></h3></div>
<img src="<%= champion.img %>" class="ChampionImage__ChampImage-xj39xo-2 fhAQxz">
<div class="h5 mb-0 font-weight-bold text-gray-800"><%= champion.key %></div>
</div>
<div class="col-auto">
<i class="fas fa-calendar fa-2x text-gray-300"></i>
</div>
</div>
</div>
</div>
</div>
<% }) %>
In my case, I've used <img src="<%= image %>" and it worked.
Of course, the code should work only in case of correctly parsed JSON.
Hi please need help how to render my multinode tree picker value (http://screencast.com/t/NTu1NqXsTmBz) to show it on its parent node named PORTFOLIO ..
i want the multinode picker value should be placed between the Portfolio and About section (http://screencast.com/t/F0Dnnv9a) but I don't know how yet i tried render it and still not work ..
here is the finish template : screencast.com/t/ar1zeZ43Pf6J
Node tree picker code:
#if (Model.Content.HasValue("mntp_pickContent"))
{
var bannerListValue = Model.Content.GetPropertyValue<string>("mntp_pickContent");
<div id="container" class="container-portfolio">
#foreach (var item in bannerListValue.Split(','))
{
var page = Umbraco.Content(item);
<div class="col-md-4 element branding">
<div class="portfolio-item flip ">
<div class="flip-content">
<div class="front">
<img width="360" height="249" src="#page.Url" class="attachment-project-thumb wp-post-image" alt="background4" />
</div>
<div class="back">
<div class="back-content">
<h4>#page.contentTitle</h4>
<div class="txt-project">
<p>#page.contentsubTitle</p>
</div>
<i class="fa fa-plus"></i> More
</div>
</div>
</div>
</div>
<!-- flip container -->
</div>
}
</div>
}
Parent Node Portfolio.cshtml
#{ if (Model.Content.HasValue("port_backImage"))
{
var bgport = Umbraco.TypedMedia(Model.Content.GetPropertyValue<string>("port_backImage"));
<section class="section-wrap section-portfolio" style="background-image: url(#bgport.Url)" id="portfolio">
<div class="container">
<div class="container-wrap row portfolio">
<div class="container-wrap-title col-md-6">
<h2>#Model.Content.GetPropertyValue("pageTitle")</h2>
<h6>#Model.Content.GetPropertyValue("subTitleText")</h6>
</div>
<div class="container-wrap-subnav col-md-6">
<ul class="subnavigation" id="filters">
<li class="active">show all</li>
#foreach (var portMenu in Model.Content.Children)
{
<li>#portMenu.Name</li>
}
</ul>
</div>
</div>
</div>
</section>
}
}
This all depends on the Templating Engine you are using.
If you are using MVC, then you need to add your MNTP logic to a partial view.
See the following link:
https://our.umbraco.org/documentation/Reference/Templating/Mvc/partial-views
If you are using WebForms, then you will need to add your logic to a Razor file OR alternatively a UserControl (.ascx) file. See the following links:
https://our.umbraco.org/documentation/reference/templating/macros/
https://our.umbraco.org/documentation/reference/templating/macros/Razor/
http://umbraco.com/help-and-support/video-tutorials/introduction-to-umbraco/developer-introduction/using-net-user-controls