Jump to content

Liam88

Members
  • Posts

    53
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

Liam88's Achievements

Full Member

Full Member (4/6)

11

Reputation

  1. I'd prefer to not use iframe but when searching it was flagged as the best option. Any suggestions instead of iframe. I'm not a dev so just learn as I go, so any direction to go would be appreciated.
  2. Yeah the purpose is to have a page but without the function. However, it will still adjust to device etc. Like you said, I may need to rethink it as I can't find distinct yes or no's on this usage.
  3. I was able to get it to work within a basic index.html file and referencing the file in an iframe. I'm guessing it's due to server settings then.
  4. I'm hoping someone may be able to guide on this. One of my side projects stores ads for ecommerce brands for inspiration. I want to now add in their landing pages. I have used SingleFile to get a download of a page and then uploaded it to the page as a file. I am then looking to output as an iframe with the expectation this won't interfere with any css/html on my page. This leads to a basic output of this <iframe src='<?=$page->landing_page_html?>' width='100%' height='600px'></iframe> However, I'm getting a 403 response on the page. Does anyone have any guidance if my method is on the right path or should I leave this for another? I'm guessing it's wrong as no other site like awwwards or say Shopify templates do this and lean on a screenshot that links to the page. I have attached an example file for context. Big thank you in advance. Collagenic Burn Elite – Obvi (11_04_2024 17_38_24).html
  5. Hey, I have the usual CKeditor set up with the insert image(s) button. I have done some googling but struggling to find a way to add video support in that bar. Does anyone have any advice they could offer. Thanks
  6. Yeah I'll have to search if there are any other threads for markup regions strat. Getting the same output with the suggestion above so did a bit of searching and found this - https://processwire.com/blog/posts/processwire-2.6.8-brings-new-version-of-reno-admin-theme-and-more/#new-this-gt-halt-method-for-use-in-template-files Adding $this->halt to the end of each case prevents the continued render when using it within _init.php (the prepended file). This does not work if just adding to _main.php. This is the action area now - <?php if($config->ajax && $input->post->bookmark){ bd($input->post->bookmark); // debug with tracy, uncomment if you have it $bookmarkid = $sanitizer->int($input->post->bookmark); $action = $sanitizer->name($input->post->action); $bookmarks = $user->getUnformatted('bookmarks'); switch($action) { case 'save': // save logic if(!$bookmarks->has($bookmarkid /* this was bookmark, now bookmarkid */)) { // add bookmark $bookmarks->add($bookmarkid /* same change here */); $user->setAndSave('bookmarks', $bookmarks); $message = 'Borat saved bookmark "'. $bookmark->id .'" ?'; $this->halt(); } else { $message = 'Nothing done'; } $success = true; break; case 'remove': // remove logic if($bookmarks->has($bookmarkid)) { $bookmarks->remove($bookmarkid); $user->setAndSave('bookmarks', $bookmarks); $message = 'Borat removed bookmark "'. $bookmark->id .'" ❌'; $this->halt(); } else { $message = 'Nothing done'; } $success = true; break; default: $message = 'error'; $success = false; } $json = array( 'id' => $bookmarkid, 'action' => $action, 'message' => $message, 'success' => $success ); header('Content-Type: text/json; charset=utf-8'); echo json_encode($json); return; } ?> Now I get this within preview: and FINALLY it now saves into the user area. A huge thank you @flydev ??. Learnt so much through this thread and hoping it helps others! I'll even keep in borat in recognition of your input.
  7. So another update Script looks like this - jQuery(document).ready(function($) { // when clicked, send ajax request to server $('button.bookmark').on('click', function(e) { var btn = $(this).hasClass('clicked') ? false : $(this).addClass('clicked'); if (!btn) { console.warn(`⚠️ Bookmark already saved to profile`); return false; } $.post('<?=$pages->get('/')->url?>', { action: $(this).val(), bookmark: btn.data('id') }) .done(function(data) { console.log(data, "? response from ajax req"); console.info(`✅ Bookmark id => ${data.id} ${data.action} `); }); }); }); I have put this in _main.php (all template is appended to this via config.) at the top so before anything. I just included it within the namespace opening within the template. I left out the if user is logged in as this feature will only be available for logged in users. <?php namespace ProcessWire; if($config->ajax && $input->post->bookmark){ bd($input->post->bookmark); // debug with tracy, uncomment if you have it $bookmarkid = $sanitizer->int($input->post->bookmark); $action = $sanitizer->name($input->post->action); $bookmarks = $user->getUnformatted('bookmarks'); switch($action) { case 'save': // save logic if(!$bookmarks->has($bookmark)) { // add bookmark $bookmarks->add($bookmark); $user->setAndSave('bookmarks', $bookmark); $message = 'Borat saved bookmark "'. $bookmark->id .'" ?'; } else { $message = 'Nothing done'; } $success = true; break; case 'remove': // remove logic if($bookmarks->has($bookmark)) { $bookmarks->remove($bookmark); $user->setAndSave('bookmarks', $bookmarks); $message = 'Borat removed bookmark "'. $bookmark->id .'" ❌'; } else { $message = 'Nothing done'; } $success = true; break; default: $message = 'error'; $success = false; } // build the response data array that will be returned in `data` from `.done(function(data) {` $json = array( 'id' => $bookmarkid, 'action' => $action, 'message' => $message, 'success' => $success ); // convert data and send as JSON header('Content-Type: text/json; charset=utf-8'); // forgot this line echo json_encode($json); return; } ?> So now I get this within preview (video below). Still full html render output (Any thoughts why would this be?) but now the JSON is appended. I have also tried placing the if AJAX within the _init.php file. This just prepends it (expected) to before the HTML output. So I suppose my issue is I'm rendering the full HTML output as the JSON just shows as part of it. Untitled (6).mp4
  8. AHH awesome, I thought it had to go somewhere. I wasn't sure whether keep in the loop but remove the action line like you mentioned.
  9. The preview just renders the page HTML. It isn't giving a JSON breakdown. So you're getting the JSON response, I'm getting a full page render. Once back on later I'll update with a. Screenshot.
  10. Thanks again @flydev ?? Correct, all is within a single template. This is then appended to _main.php. The full template is in my reply above. To be honest I'm stuck on this so instead of this seeming like a game of circles I'll take some time out to get to grips with it. From what I can tell, I can not see anything wrong but again that is my lower knowledge barrier. On button click, I do not get anything firing in console. When I click a second time I then get "⚠️ Bookmark already saved to profile" A quick question, should any of this part be included and should it be within the loop? <?php if($user->isLoggedin() && $action) { $bookmarks = $user->getUnformatted('bookmarks'); if($action === 'remove') { // remove bookmark if($bookmarks->has($posts)) $bookmarks->remove($posts); } else if($action === 'save' && !$bookmarks->has($posts)) { // add bookmark $bookmarks->add($posts); } // save bookmarks $user->setAndSave('bookmarks', $bookmarks); $this->halt(); } ?> Within console -> network I get this when clicking a button and within network -> preview I just get the full page html which I'm guessing shouldn't be the case. This is the page in question - https://ad-bank.co.uk/all-ads/ Untitled (5).mp4 Anyway, I'll take some time out to get to grips on this but appreciate all the info and direction on this.
  11. As always, thank you @flydev ?? Straight implementing your snip I'm getting undefined response - This is the whole template file for /all/ url mentioned above. From what I can see it's implemented right?... So where you mention the "only one loop" is where I have placed the main template build. <?php namespace ProcessWire; $items = $pages->find($selector); //selector built in _func template $total = $items->getTotal(); if($config->ajax && $input->post->bookmark){ bd($input->post->bookmark); // debug with tracy, uncomment if you have it $bookmarkid = $sanitizer->int($input->post->bookmark); $action = $sanitizer->name($input->post->action); switch($action) { // which action ? case 'save': // save logic $message = 'Borat saved bookmark "'. $bookmarkid .'" ?'; $success = true; break; case 'remove': // remove logic $message = 'Borat removed bookmark "'. $bookmarkid .'" ❌'; $success = true; break; default: $message = 'error'; $success = false; } // build the response data array that will be returned in `data` from `.done(function(data) {` $json = array( 'id' => $bookmarkid, 'action' => $action, 'message' => $message, 'success' => $success ); // convert data and send as JSON header('Content-Type: text/json; charset=utf-8'); // forgot this line echo json_encode($json); return; } ?> <div id="content-main" class="adbank" pw-append> <!-- start of page header --> <header class="small-header"> <div class="full-width"> <div class="row flex header-content"> <h1><?php echo $page->headline ?></h1> <?php if ($page->summary != ''){ echo''.$page->summary.''; } ?> </div> </div> </header> <!-- end of page header --> <div class="bread-plus-filter"> <div class="full-width"> <div class="row flex">'; <!-- Breadcrumbs for all pages except home page --> <?php include_once "inc/breadcrumb.php"; ?> <div class="filter-surround"> <div class="filter-row"> <p><?=$total?> Results</p> <!-- filter button --> <button class="button filter-toggle open-menu" type="button" aria-label="Toggle filter"> Filter </button> </div> </div><!-- close of filter surround --> </div> </div> </div> <!-- Main blog post section --> <section id="main-post-area" class="ab-post-area"> <div class="full-width"> <?php if(count($items) > 0){ }else{ echo'<h2>Sorry, no results match that filter</h2>'; } ?> <div class="row"> <!-- main creative grid --> <div class="creative-posts-container grid"> <!-- colcade columns --> <div class="grid-col grid-col--1"></div> <div class="grid-col grid-col--2"></div> <div class="grid-col grid-col--3"></div> <!-- loop out the posts from the selector --> <?php foreach($items as $posts): ?> <div class="creative-post grid-item <?=$posts->ab_channels->title?> <?=$posts->ab_placement->title?> <?=$posts->ab_content->title?> <?=($posts->check_1 ? ' no-title' : '')?> <?=($posts->image_1->height / $posts->image_1->width >= 1.5 ? 'long' : 'short')?> "> <div class="creative-post-options"> <!-- posts buttons including view brand, view post and save --> <div class="actions"> <a href="<?=$posts->adbank_brands->{httpUrl}?>" class="action" role="link" aria-label="View more of <?=$posts->adbank_brands->{title}?>" title="View more of <?=$posts->adbank_brands->{httpUrl}?>">View Brand</a> <a href="<?=$posts->httpUrl?>" class="action" role="link" aria-label="see more info about this advert" title="see more info about this advert">View Ad</a> <?php if($user->isLoggedin()): ?> <!-- if user is logged in --> <?php if($user->bookmarks->has($posts)): ?> <!-- if user has saved then show this button --> <button class="button action" type='submit' name='saved' value='saved' disabled>Saved</button> <?php else: ?> <!-- if they haven't saved then show this button to add this page to bookmarks --> <button class="button bookmark action" type='submit' name='bookmark' value='save' data-id='<?=$posts->id?>'>Save</button> <!-- changed to $posts->id from bookmarksId to match the foreach output --> <?php endif; ?> <?php else: ?> <!-- if user is not logged in then show this button to fire a login modal --> <button class="button action save-modal" role="button" title="save this ad bank post" aria-label="save this ad bank post" href="">Save</button> <?php endif; ?> </div> </div> <!-- loop through posts type and include the relevant markup --> <?php if($posts->ab_channels->title === "facebook-ads"){ include "inc/adbank/facebook-ads.php"; }else if($posts->ab_channels->title === "instagram-ads"){ include "inc/adbank/instagram-ads.php"; }else if($posts->ab_channels->title === "pinterest-ads"){ include "inc/adbank/pinterest-ads.php"; }else if($posts->ab_channels->title === "youtube-ads"){ include "inc/adbank/youtube-ads.php"; }else if($posts->ab_channels->title === "display-ads"){ include "inc/adbank/display-ads.php"; }else if($posts->ab_channels->title === "tiktok-ads"){ include "inc/adbank/tiktok-ads.php"; }else if($posts->ab_channels->title === "podcast"){ include "inc/adbank/podcast.php"; }else{ } ?> </div> <?php endforeach ?> </div><!-- end of main creative grid --> </div><!-- End row --> </div><!-- End container --> </section><!-- End section --> <!-- pagination --> <?php echo pagination($items); ?> <!-- AJAX request --> <script> jQuery(document).ready(function($) { // when clicked, send ajax request to server $('button.bookmark').on('click', function(e) { var btn = $(this).hasClass('clicked') ? false : $(this).addClass('clicked'); if (!btn) { console.warn(`⚠️ Bookmark already saved to profile`); return false; } $.post('<?= $page->url?> /*should this be $posts->URL>*/', { action: $(this).val(), bookmark: btn.data('id') }) .done(function(data) { console.log(data, "? response from ajax req"); console.info(`✅ Bookmark id => ${data.id} ${data.action} `); }); }); }); </script> <!-- end of AJAX request --> </div> <!-- end of content surround -->
  12. Kinda fun so may look too once completed and given a clean up.
  13. Just an update again. So I have the AJAX working on the single page. See below woop! Untitled (4).mp4 Next steps is trying to get this to work with a variable input. I have taken your jquery snip @flydev ??, again thank you. Right now I'm just trying to get it to work on this page which has a loop of posts - https://ad-bank.co.uk/all-ads/ This is where I'm at. The main button section. Only showing a "save" button if the user has not saved the page. <?php if($user->isLoggedin()): ?> <?php if($user->bookmarks->has($posts)): ?> <button class="button bookmark action" type='submit' name='bookmark' disabled>Saved</button> <?php else: ?> <!-- show button to add this page to bookmarks --> <button class="button bookmark action" type='submit' name='bookmark' value='save' data-id='<?=$posts->url?>'>Save</button> <?php endif; ?> <?php endif; ?> Next is the action element shown above. This is also within the foreach loop so it is repeated for each button. I found this was the only way I could get it to capture the button action. Is there a better way to do this without having this action snip repeated for each button? Would it be using the data id attribute which could then sit outside of the loop? <?php $action = $input->post->option('bookmark', [ 'save', 'remove'] ); if($user->isLoggedin() && $action) { $bookmarks = $user->getUnformatted('bookmarks'); // I have now removed "remove" from the button section. Kept it in just in case I do wish to use it. if($action === 'save' && !$bookmarks->has($posts)) { // add bookmark $bookmarks->add($posts); } // save bookmarks $user->setAndSave('bookmarks', $bookmarks); $this->halt(); } ?> Then I have the AJAX request here. This now takes the button data id attribute instead of <?= $page->url ?>. This I found means it grabs the correct url instead of the first url on page that is not saved. $(document).ready(function($) { // when clicked, send ajax request to server $('button.bookmark').on('click', function() { var btn = $(this).hasClass('clicked') ? false : $(this).addClass('clicked'); // I am passing data id instead of page->url as it will capture the button value needed. Not sure if correct, console shows the correct value. if(btn) $.post($(this).data('id'), { action: $(this).val(), bookmark: btn.data('id') }) .done(function(data) { //do something console.info(`✅ Bookmark id => ${btn.data('id')} saved to user profile`); }); }); }); So in console I get a successful output (see below) but it's not saving into the user. Any thoughts why this might be? I'm thinking it's the action part of this but not sure. Overall, feels good to be making progress on this and learning. If anyone has input on the above issues please fire over. Cheers
  14. Thanks @flydev ?? Tbh I need to spend time to learn more about AJAX and implementation. I'll try implement this on the single option page so /all/page-name/ and then work on the /all/. Unless based on the above, I don't need dedicated versions for each page? Again, will have to get digging into AJAX this week. Cheers
  15. To update where I'm at. So I have - Added a page ref field to the user template Created a front end button that adds or removes the page id to/from the page ref field. This means the like module is not needed as I'm not looking to allow anon users to save, only logged in users. This is the button. I will most likely remove the "remove" button and just have a "saved" item to signify it's saved. I'll allow users to remove in their profile area which outputs their saved posts. <?php if($user->isLoggedin()): ?> <form action='<?=$page->url?>' method='post'> <?php if($user->bookmarks->has($page)): ?> <!-- user already has this page in their bookmarks, show remove button --> <button class="button save-button" type='submit' name='bookmark' value='remove'>Remove</button> <?php else: ?> <!-- show button to add this page to bookmarks --> <button class="button save-button" type='submit' name='bookmark' value='add'>Save</button> <?php endif; ?> </form> <?php endif; ?> This is then be actioned by the below. $action = $input->post->option('bookmark', [ 'add', 'remove'] ); if($user->isLoggedin() && $action) { $bookmarks = $user->getUnformatted('bookmarks'); if($action === 'remove') { // remove bookmark if($bookmarks->has($page)) $bookmarks->remove($page); } else if(!$bookmarks->has($page)) { // add bookmark $bookmarks->add($page); } // save bookmarks $user->setAndSave('bookmarks', $bookmarks); // always good to redirect back to self after POST save request $session->redirect($page->url, false); } This works great for the actual post page. So url example being website.com/all/page-name/ However, I have a foreach on website.com/all/ and have the save button on each foreach output. These in the foreach are called $posts. I have been able to get it to work by adjusting the above to be $posts instead of $page. However, I find that it just sends the user to the $posts URL but I'd want them to stay on the current page. I did this posts suggestion: However, I find it doesn't redirect to the /all/ page but goes to /all/page-name/ I also saw a suggested version below to AJAX it which would remove the redirect issue in /all/. So removal of the form element and I'm doing the button show/hide through PHP instead of JS. The snip below doesn't do anything right now and I'm not too sure why. Any input from someone with JS/AJAX knowledge is appreciated. <?php if($user->isLoggedin()): ?> <?php if($user->bookmarks->has($posts)): ?> <!-- user already has this page in their bookmarks, show remove button --> <button class="button save-button" name='bookmark' value='remove'>Remove</button> <?php else: ?> <!-- show button to add this page to bookmarks --> <button class="button save-button" name='bookmark' value='add'>Save</button> <?php endif; ?> <?php endif; ?> <script> jQuery(document).ready(function($) { // when clicked, send ajax request to server $('button.bookmark').on('click', function() { var btn = $(this).hasClass('clicked') ? false : $(this).addClass('clicked'); if(btn) $.post('<?= $posts->url ?>', { bookmark: btn.val() }) .done(function(data) { }); }); }); </script> Feels good to get this working but just need to hone in the user experience and behaviour. If anyone wants to see the page in question it's here Liam
×
×
  • Create New...