Correct YAML syntax from frontmatter - yaml

I need to achieve this frontmatter:
services:
- service:
serviceName: Service 1
serviceDesc: Blah
- service:
serviceName: Service 2
serviceDesc: Blah
- service:
serviceName: Service 3
serviceDesc: Blah
Here is my current Yaml syntax:
services:
service:
- serviceName: Water Treatment
serviceDesc: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua.
- serviceName: Environmental Services
serviceDesc: Lorem ipsum dolor sit amet, consectetur adipiscing eliy, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua.
I am using Netlify CMS to create this but I cannot find a solution to get an individual service to use with Nunjucks.
Any help would be amazing.

Seeing your config.yml file would help, but from the look of your current output, I will assume that it looks something like this:
- label: 'Services'
name: 'services'
widget: 'object'
fields:
- label: 'Service'
name: 'service'
widget: 'list'
fields:
- { label: 'Name', name: 'serviceName', widget: string }
- { label: 'Description', name: 'serviceDesc', widget: text }
In you case, you want the service node to be one level lower, wrapping each list element, so you should be able to just switch the position of your object and list widgets like so:
- label: 'Services'
name: 'services'
widget: 'list'
fields:
- label: 'Service'
name: 'service'
widget: 'object'
fields:
- { label: 'Name', name: 'serviceName', widget: string }
- { label: 'Description', name: 'serviceDesc', widget: text }

Related

Call a WebAPI in ASP.Net Core MVC

I have programmed a backend system in which I can manage data and then output it to an API. I did this because I want to convert a large project to a different language + framework, but I still want to integrate this backend system into the current version first, because it is much better than the old way. I have been looking for days how it works but I haven't really come to a result, I hope someone can help me.
example:
I have a separate page for each member with some data from a biography etc. and I can have this displayed in the WebAPI under: "https://sub.domain.de/items/member" then all members and associated data is output. Now I want that I to: "https://www.domain.de/member/[John_Doe]" (John_Doe is of course an example value for every other member)
can output certain data. the pages should of course still be generated dynamically.
ps: if it is necessary I can also enter "https://sub.domain.de/items/member/[John_Doe]" to only get the data from a specific member.
the json basically looks like this:
{
"data": [
{
"name": "John_Doe",
"status": "published",
"user_created": "052a2c25-b063-4a82-90cb-110d7f809cae",
"date_created": "2021-06-29T08:30:06+02:00",
"title": "Doc John Doe",
"Characteristics": "- **Lorem **: ipsum dolor sit amet\n- **Birthdate**: 1965",
"bio": "- **Lorem ipsum**:\nLorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.",
"member": true,
"section1": false,
"section2": false,
"portrait": null
},
{
"name": "Jane",
"status": "published",
"sort": null,
"user_created": "052a2c25-b063-4a82-90cb-110d7f809cae",
"date_created": "2021-06-29T08:29:31+02:00",
"title": "Jane",
"Characteristics": "",
"bio": "Bio unbekannt.",
"member": true,
"section1": false,
"section2": true,
"potrait": "30d17fe3-bcf7-4aa2-9759-49f3e257eb0f"
}
]
}
and the bio and the characteristics are written in markdown.
I hope I was able to explain what I mean and someone can help me.
edit:
ps: my main problem is that i don't know how to get data from an api, and of course i not only have the area with the members, i still have a lot of articles and more but it works with the same logic.
I guess this totally depending in the routing. you can construct your api that returned the data with this url :"https://sub.domain.de/items/member/[John_Doe]" like so
[Route("items/member")]
[ApiController]
public class UserController : ControllerBase
{
[HttpGet("{username}")]
public IActionResult GetUserData(string username) {
// your logic
}
}

Nativescript RadListView StaggeredLayout Issue

I have a Nativescript Angular project where I am using RadListView trying to use the staggered layout. It works fine on Android but on iOS there is a spacing issue that I cannot figure out what is causing it.
HTML
<GridLayout class="page page-content" rows="*">
<GridLayout margin="10">
<RadListView height="100%" [items]="dataItems">
<ng-template tkListItemTemplate let-item="item" backgroundColor="transparent">
<StackLayout rows="auto, auto" borderWidth="1" borderColor="#ccc" margin="10">
<Label class="h3" [text]="item.name"></Label>
<Label class="descriptionLabel" [text]="item.description" textWrap="true"></Label>
</StackLayout>
</ng-template>
<ListViewStaggeredLayout tkListViewLayout scrollDirection="Vertical" spanCount="2"></ListViewStaggeredLayout>
</RadListView>
</GridLayout>
</GridLayout>
TypeScript
dataItems = [{name: "Item 1", description: "Lorem ipsum dolor sit amet."},
{name: "Item 2", description: "Maecenas ac massa eu odio porta efficitur at non leo"},
{name: "Item 3", description: "Nunc vitae tortor sodales, varius magna quis, faucibus justo."},
{name: "Item 4", description: "In finibus sem"},
{name: "Item 5", description: "Duis sed sem porttitor"},
{name: "Item 6", description: "Blandit est vel, viverra nisi."},
{name: "Item 7", description: "Etiam at nisl ultricies, consectetur libero non, iaculis est."},
{name: "Item 8", description: "Curabitur at lorem"},
{name: "Item 9", description: "Non lectus tempus congue ultricies eget tellus."},
{name: "Item 10", description: "In sed dolor sit amet velit tempus iaculis."},
{name: "Item 11", description: "Duis dictum nunc in neque"},
{name: "Item 12", description: "Mauris dignissim mi sit amet nulla tristique, id posuere urna volutpat mauris gravida purus."},
{name: "Item 13", description: "Etiam accumsan sapien eget eros convallis porttitor."},
{name: "Item 14", description: "Vivamus ac arcu"},
{name: "Item 15", description: "Vestibulum at elit eget sapien fringilla"},
{name: "Item 16", description: "Maecenas tempus enim et velit bibendum, eu consequat erat volutpat."}];
I'm unable to reproduce the issue on my end either with or without the extra GridLayouts. At least in my opinion those layouts are not required actually. Here is the link to Playground.

Trying to get property 'id' of non-object in laravel session foreach

Im practicing laravel and right now Im in the session topic
this is my controller
public function set(Request $request){
$product = Product::findOrFail($request->input('id'));
session()->put('product', $product);
return redirect()->route('cart');
}
when i tried to echo the{{session()->get('product')}} on my blade it produce an output of
{
"id":9,
"name":"Lorem ipsum dolor sit amet",
"description":"Proin pretium, mauris id convallis tempus, lorem enim tincidunt nulla, vel pharetra sapien odio eget ligula. Sed maximus, massa sit amet condimentum bibendum, nisi ante vestibulum ipsum, ut ornare justo lorem mollis justo.",
"price":"22.21",
"cover_image":"JRwg9TSKTvUTvuij.jpg",
"created_at":"2018-07-20 03:47:57",
"updated_at":"2018-07-20 03:47:57"
}
but when i tried to use foreach on it by using
#foreach(session()->get('product') as $key)
{{$key->id}}
#endforeach
it shows an error of Trying to get property 'id' of non-object
can someone guide me why I'm I getting this error thanks.
You are iterating through your single object but what you seem to need to do is:
{{ session()->get('product')->id }}
If you want to loop then you can do:
#foreach (session()->get('product')->toArray() as $key => $value)
{{ $key }}: {{ $value }}
#endforeach
This will result in:
id: 9
name: Lorem ipsum dolor sit amet
description: Proin pretium, mauris id convallis tempus, lorem enim tincidunt nulla, vel pharetra sapien odio eget ligula. Sed maximus, massa sit amet condimentum bibendum, nisi ante vestibulum ipsum, ut ornare justo lorem mollis justo.
price: 22.21
cover_image: JRwg9TSKTvUTvuij.jpg
created_at: 2018-07-20 03:47:57
updated_at: 2018-07-20 03:47:57
However, just as a sidenote this is bad practice because your coupling your view with a session entry. Ideally your view would just take a product object as a view parameters and use that directly. That way you can pass it that object either from the session or from a database query.
If you are trying to get single value from an object you can get like this.
{{ session()->get('product')->id }}
Or If you wish to print all data, First you have to convert object into an array then use foreach.
#foreach (session()->get('product')->toArray() as $key => $value)
{{ $key }}: {{ $value }} </br>
#endforeach
Try it this way :
#foreach(session()->get('product') as $key)
{{$key['id']}}
#endforeach
You are trying to iterate an object. When you try to do this you get the public properties from the object. In your example $key is one of those properties, not the model itself.
When you echo {{ }} a Model __toString gets called which returns the serialized model as json.
If you want that model's id you can just grab it like normal. session('product')->id
If you want you can serialize the Model to an array:
foreach ($model->toArray() as $key => $value) {
...
}

Laravel check if Request has collection

I want to run an if statement over each of my posted requests and if any are a collection do something different.
When I die dump $request->all I have an array that looks like this;
"_token" => "MMRFBAgyThsIHzITzT26Qwdp4L6HDV0JTPGs6h"
"page_name" => "Travel"
"heading" => "Travel Europe"
"textarea" => "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostru ▶"
"seo_title" => "travel"
"seo_description" => "travel"
"attribute_1" => "Food"
"attribute_2" => "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor."
"attribute_3" => "Hotels"
"attribute_6" => "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor."
"attribute_5" => "Events"
"attribute_4" => "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor."
"attribute_7" => null
"attribute_8" => null
"attribute_9" => UploadedFile {#233 ▶}
The data will be different so I can't write anything static e.g.$request->input('attribute_9')
This is how I'm currently handling the attributes which are the unknown requests.
$input = $request->all();
foreach($input as $key=>$value) {
if(strstr($key,'attribute_')) {
$i = str_replace("attribute_", "", $key);
if (!empty($value)) {
if ($value instanceof Illuminate\Http\UploadedFile) {
dd('lets have a collection...');
}
Attribute::where('id', $i)->update(['value' => $value]);
} else{
Attribute::where('id', $i)->update(['value' => '']);
}
}
}
You can see I've tried to check the $value using instanceOf but that hasn't worked. The if statement is never true and the page just returns.
Example of attribute input submission -
#if($comp_attr['data_type'] == 'file')
<div class="form-grp img-form" style="width: {{ $comp_attr['width'] }}%;">
<label>Banner Image</label>
<span class="img-hold">
{{ $banner }}
</span>
<input type="{{ $comp_attr['field_type'] }}" name="attribute_{{ $comp_attr['id'] }}" />
</div>
#else
<div class="form-grp" style="width: {{ $comp_attr['width'] }}%;">
<label>{{ $comp_attr['label'] }}</label>
<input type="{{ $comp_attr['field_type'] }}" name="attribute_{{ $comp_attr['id'] }}" value="{{ $comp_attr['value'] }}" />
</div>
#endif
I believe you are trying to get the $_FILES
So you can get all the files using
$request->allFiles();
This will return you all the files in the request. then you can perform any action on it.
Hope this helps
Instead of
name="attribute_{{ $comp_attr['id'] }}"
Try
name="attributes[{{ $comp_attr['id'] }}]"
Notice the new 's' ^ , and the brackets on either side of the {{ }}
By using brackets we convert it to an associative array, keyed by the blade variable.
Then on the php side you can do something like this:
foreach($request->get('attributes') as $i => $value)
{
...
}

2 identical YAML files but one doesn't display all the information?

I'm really puzzled.
When I open the terminal and do: php symfony doctrine:data-load having this file in my fixtures directory:
JobeetJob:
job_sensio_labs:
JobeetCategory: programming
type: full-time
company: Sensio Labs
logo: sensio-labs.gif
url: http://www.sensiolabs.com/
position: Web Developer
location: Paris, France
description: |
You've already developed websites with symfony and you want to work
with Open-Source technologies. You have a minimum of 3 years
experience in web development with PHP or Java and you wish to
participate to development of Web 2.0 sites using the best
frameworks available.
how_to_apply: |
Send your resume to fabien.potencier [at] sensio.com
is_public: true
is_activated: true
token: job_sensio_labs
email: job#example.com
expires_at: '2010-10-10'
job_extreme_sensio:
JobeetCategory: design
type: part-time
company: Extreme Sensio
logo: extreme-sensio.gif
url: http://www.extreme-sensio.com/
position: Web Designer
location: Paris, France
description: |
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in.
Voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa
qui officia deserunt mollit anim id est laborum.
how_to_apply: |
Send your resume to fabien.potencier [at] sensio.com
is_public: true
is_activated: true
token: job_extreme_sensio
email: job#example.com
expires_at: '2010-10-10'
expired_job:
JobeetCategory: programming
company: Sensio Labs
position: Web Developer
location: Paris, France
description: Lorem ipsum dolor sit amet, consectetur adipisicing elit.
how_to_apply: Send your resume to lorem.ipsum [at] dolor.sit
is_public: true
is_activated: true
created_at: '2005-12-01 00:00:00'
token: job_expired
email: job#example.com
# Starts at the beginning of the line (no whitespace before)
<?php for ($i = 100; $i <= 130; $i++): ?>
job_<?php echo $i ?>:
JobeetCategory: programming
company: Company <?php echo $i."\n" ?>
position: Web Developer
location: Paris, France
description: Lorem ipsum dolor sit amet, consectetur adipisicing elit.
how_to_apply: |
Send your resume to lorem.ipsum [at] company_<?php echo $i ?>.sit
is_public: true
is_activated: true
token: job_<?php echo $i."\n" ?>
email: job#example.com
<?php endfor ?>
Everythings goes fine.
But If I replace it for this one (every cutting and pasting the code without replacing the file):
JobeetJob:
job_sensio_labs:
JobeetCategory: programming
type: full-time
company: Sensio Labs
logo: sensio-labs.gif
url: http://www.sensiolabs.com/
position: Web Developer
location: Paris, France
description: |
You've already developed websites with symfony and you want to work
with Open-Source technologies. You have a minimum of 3 years
experience in web development with PHP or Java and you wish to
participate to development of Web 2.0 sites using the best
frameworks available.
how_to_apply: |
Send your resume to fabien.potencier [at] sensio.com
is_public: true
is_activated: true
token: job_sensio_labs
email: job#example.com
expires_at: '2009-02-28'
job_extreme_sensio:
JobeetCategory: design
type: part-time
company: Extreme Sensio
logo: extreme-sensio.gif
url: http://www.extreme-sensio.com/
position: Web Designer
location: Paris, France
description: |
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in.
Voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa
qui officia deserunt mollit anim id est laborum.
how_to_apply: |
Send your resume to fabien.potencier [at] sensio.com
is_public: true
is_activated: true
token: job_extreme_sensio
email: job#example.com
expires_at: '2009-01-30'
expired_job:
JobeetCategory: programming
company: Sensio Labs
position: Web Developer
location: Paris, France
description: Lorem ipsum dolor sit amet, consectetur adipisicing elit.
how_to_apply: Send your resume to lorem.ipsum [at] dolor.sit
is_public: true
is_activated: true
expires_at: '2005-12-01 00:00:00'
token: job_expired
email: job#example.com
# Starts at the beginning of the line (no whitespace before)
<?php for ($i = 100; $i <= 130; $i++): ?>
job_<?php echo $i ?>:
JobeetCategory: programming
company: Company <?php echo $i."\n" ?>
position: Web Developer
location: Paris, France
description: Lorem ipsum dolor sit amet, consectetur adipisicing elit.
how_to_apply: |
Send your resume to lorem.ipsum [at] company_<?php echo $i ?>.sit
is_public: true
is_activated: true
token: job_<?php echo $i."\n" ?>
email: job#example.com
<?php endfor; ?>
The info in job_extreme_sensio is stored in the database but not displayed in the browser.
Any suggestions?
Are these differences significant for you?
--- php1 2010-08-11 16:02:28.000000000 +0200
+++ php2 2010-08-11 16:02:57.000000000 +0200
## -19,7 +19,7 ##
is_activated: true
token: job_sensio_labs
email: job#example.com
- expires_at: '2010-10-10'
+ expires_at: '2009-02-28'
job_extreme_sensio:
JobeetCategory: design
## -45,7 +45,7 ##
is_activated: true
token: job_extreme_sensio
email: job#example.com
- expires_at: '2010-10-10'
+ expires_at: '2009-01-30'
expired_job:
JobeetCategory: programming
## -56,7 +56,7 ##
how_to_apply: Send your resume to lorem.ipsum [at] dolor.sit
is_public: true
is_activated: true
- created_at: '2005-12-01 00:00:00'
+ expires_at: '2005-12-01 00:00:00'
token: job_expired
email: job#example.com
## -75,4 +75,4 ##
token: job_<?php echo $i."\n" ?>
email: job#example.com
-<?php endfor ?>
+<?php endfor; ?>

Resources