Categories list in Piranha CMS? - piranha-cms

I'm using Piranha Core 8 with Aspnetcore 3. So far everything is going well. (I love Piranha!)
My current problem is when building a Sidebar with a list of categories.
I can't figure out how to retrieve all categories from the Api.
So far, I can get a list of posts, and perhaps iterate over them to collect the categories but this seems inefficient.
Any one know how to retrieve a list of all the categories from the cshtml pages?

You can get the full list of taxonomies per Archive by calling the Api.
var categories = await api.GetAllCategoriesAsync(archiveId);
var tags = await api.GetAllTagsAsync(archiveId);
Best regards

From the razor page I got it working this way :
#{
var archiveId = WebApp.CurrentPost == null ? WebApp.CurrentPage.Id : WebApp.CurrentPost.BlogId;
var categories = await WebApp.Api.Posts.GetAllCategoriesAsync(archiveId);
var tags = await WebApp.Api.Posts.GetAllTagsAsync(archiveId);
}

Related

How to retrieve the Id of a newly Posted entity using ASP.Net Core?

I Post a new Waste entity using the following code:
var result = await httpClient.PostAsJsonAsync(wasteApiRoute, waste);
The Api Controller (using the code created by VS) seems to try to make life easy for me by sending back the new Id of the Waste entity using:
return CreatedAtAction("GetWaste", new { id = waste.Id }, waste);
So the resultvariable wil contain this data. Indeed, I find it in its Headers.Location property as an url.
But how do I nicely extract the Id property from the result without resorting to regular expressions and the like? Surely the creators of ASP.Net Core will have included a nifty call for that?
Well, the best I can come up with is:
var result = await httpClient.PostAsJsonAsync(wasteApiRoute, waste);
var newWaste = await result.Content.ReadFromJsonAsync<Waste>();
Where waste has an Id of zero, newWaste has its Id set.

Podio API JS - Update relationship field of a Item

Using NodeJS, I am trying to update relationship field which link to another app (contacts-leads). I have try all combination but still getting error. I think I have the necessary data to post, app_id, item_id, external_id..etc. I need help with forming JSON structure.
p.request('put','item/<Item_Id>/value', data)
var data {....}
app_id:'<app_id>'
value:'<value>' (value is the app_item_id of the link to application; that is the number in URL)
app_item_id: '<app_item_id>'
external_id:'<external_id>'
I was able to update non-relationship field without problem.
Thanks
Well, going to answer my own question. That will work for single app link, not sure about multiple ones.
data = {
"<external_id>": {
"apps": [{"app_id": <app_id>}],
"value: <app_item_id>
}
}

MailChimp API Get Subscribers ammount

I have been looking at the mailchimp api, and am wondering how to display the live ammount of subscribers to a list, is this possible? And is it possible to have this counter LIVE? I.e as users join, the number increases in real time?
EDIT:
I have been getting used to the API slightly...
after using Drewm's mailchimp php wrapper its starting to make more sense...
I have so far
// This is to tell WordPress our file requires Drewm/MailChimp.php.
require_once( 'src/Drewm/MailChimp.php' );
// This is for namespacing since Drew used that.
use \Drewm;
// Your Mailchimp API Key
$api = 'APIKEY';
$id = 'LISTID';
// Initializing the $MailChimp object
$MailChimp = new \Drewm\MailChimp($api);
$member_info = $MailChimp->call('lists/members', array(
'apikey' => $api,
'id' => $id // your mailchimp list id here
)
);
But not sure how to display these values, it's currently just saying 'array' when I echo $member_info, this maybe completly because of my ignorance in PHP. Any advice to s
I know this may be old, but maybe this will help someone else looking for this. Latest versions of API and PHP Files.
use \DrewM\MailChimp\MailChimp;
$MailChimp = new MailChimp($api_key);
$data = $MailChimp->get('lists');
print_r($data);// view output
$total_members = $data['lists'][0]['stats']['member_count'];
$list_id = $data['lists'][0]['id'];
$data['lists'][0] = First list. If you have more, then it would be like $data['lists'][1] ect...
And to get a list of members from a list:
$data = $MailChimp->get("lists/$list_id/members");
print_r($data['members']);// view output
foreach($data['members'] as $member){
$email = $member['email_address'];
$added = date('Y/m/d',strtotime($member['timestamp_opt']));
// I use reverse dates for sorting in a *datatable* so it properly sorts by date
}
You can view the print_r output to get what you want to get.

Is there a way to display multiple collections on a single page using Backbone.js and Rails 3?

I am trying to develop a single page application using Rails 3 and backbone.js. Is there away to instantiate two different collections in a router? Or would I need two routers routing to the same route?(I don't think this is possible)
I have two collections and I don't see why this is so hard to figure out. Any ideas?
You can instantiate and fetch as many collections, models, or views you like in a single route.
function showBooksAndCars() {
var carsCollection = new App.collections.Cars();
var booksCollection = new App.collections.Books();
carsCollection.fetch();
booksCollection.fetch();
var carsView = new App.views.CarsView({collection: carsCollection}).render();
var booksView = new App.views.BooksView({collection: booksCollection}).render();
$('div.cars').replaceWith(carsView.el);
$('div.books').replaceWith(booksView.el);
}

how can I obtain all tags in rally api

We use tags to identify our completed user stories. Now we have a need to automatic that process by querying tags and generate a list of user stories that associate to that tag.
I have found the following link very useful:
Rally: Query Filtered to Specific Tags
However, I'd like to somehow query Rally so I can get a list of all the tags first so users has the freedom to pick a tag they want to query. Any idea how to accomplish that? Thanks in advance.
If you are using SDK 1.0 you can use the code below to get all allowable tags. All you should have to do it supply a function named "callback" to handle your results.
queryConfig = {
type : 'defect',
key : 'defects',
query: '(Archived = false)',
fetch: 'Name,Priority'
};
var rallyDataSource = new rally.sdk.data.RallyDataSource('__WORKSPACE_OID__',
'__PROJECT_OID__',
'__PROJECT_SCOPING_UP__',
'__PROJECT_SCOPING_DOWN__');
rallyDataSource.findAll(queryConfig, callback);